Wanted: Curl example of using ReST API to upload an image
Hi. First time poster here; experienced developer but new to Umbraco. Has anyone successfully uploaded a binary file (e.g. image) to the REST API using cURL in a Bash script? I've got as far with the REST API as authenticating and creating the media item. When I try and PUT to the 'upload' resource I'm running into problems. Looking at the Chrome dev tool for a 'normal' webUI upload request I can see that there's a multipart/form-data body with some additional fields but Chrome hides any actual file contents. I know that I have to honour the CRLF convention, and that Bash/echo is funny about quoting the \r\n. Beyond that the 'Unexpected end of MIME multipart stream.' error I'm seeing is not useful. I've read the source of the relevant REST MediaController file and can see what is supposed to be happening in the UploadFile() method but am obviously missing something. If anyone's got an actual example of a small shell script that contains the correct Bash invocation that would be really useful. Thanks.
Update: I've successfully uploaded a binary file via the backoffice API. I'd still prefer to drive this via REST, rather than mimicking a browser (lifting cookies into HTTP headers gets messy), so suggestions still gratefully received. Happy to post the cURL commands that have worked for me if anyone's interested.
I'm not all the way there yet, but I'll start to answer this myself. I'm on a Mac, so this is Bash command-line specific, but easily translated to Windows CMD. Given an Umbraco instance configured for ReST access (use the Github repo, not the NuGet package since it's actually under active development, AFAICT), some handy cURL commands:
... And there I'm drawing a blank. Worth noting I've enabled a Tags field on the Image media type and the placeholder image/media resource is being tagged correctly. I've got a command that in theory should upload a file, and seems to work (in that it returns "null" and does not error). But I'm not seeing the file either on disk on in the media section.
Wanted: Curl example of using ReST API to upload an image
Hi. First time poster here; experienced developer but new to Umbraco. Has anyone successfully uploaded a binary file (e.g. image) to the REST API using cURL in a Bash script? I've got as far with the REST API as authenticating and creating the media item. When I try and PUT to the 'upload' resource I'm running into problems. Looking at the Chrome dev tool for a 'normal' webUI upload request I can see that there's a multipart/form-data body with some additional fields but Chrome hides any actual file contents. I know that I have to honour the CRLF convention, and that Bash/echo is funny about quoting the \r\n. Beyond that the 'Unexpected end of MIME multipart stream.' error I'm seeing is not useful. I've read the source of the relevant REST MediaController file and can see what is supposed to be happening in the UploadFile() method but am obviously missing something. If anyone's got an actual example of a small shell script that contains the correct Bash invocation that would be really useful. Thanks.
Update: I've successfully uploaded a binary file via the backoffice API. I'd still prefer to drive this via REST, rather than mimicking a browser (lifting cookies into HTTP headers gets messy), so suggestions still gratefully received. Happy to post the cURL commands that have worked for me if anyone's interested.
I'm not all the way there yet, but I'll start to answer this myself. I'm on a Mac, so this is Bash command-line specific, but easily translated to Windows CMD. Given an Umbraco instance configured for ReST access (use the Github repo, not the NuGet package since it's actually under active development, AFAICT), some handy cURL commands:
... And there I'm drawing a blank. Worth noting I've enabled a Tags field on the Image media type and the placeholder image/media resource is being tagged correctly. I've got a command that in theory should upload a file, and seems to work (in that it returns "null" and does not error). But I'm not seeing the file either on disk on in the media section.
Any suggestions on what to investigate next would be gratefully received.
Hi Robin,
I am interested in seeing your cURL call. Can you please post it here and show me?
Thanks! Laura
is working on a reply...