I have to submit a form like as follows:
<input type="file" name="jpgFile"> I can't seem to find any instructions on sending this in URLExecute. If I specify the file name as the parameter it fails. If I try Import[filename, "JPG"] of the image it also fails as invalid.
I thought his might work, but I get an error "Iteration limit of 4096 exceeded". This suggests it might be working as test file is 451,107 bytes.
URLExecute[ url, "Method" -> "POST", "Headers" -> { "Accept" -> "application/json; charset=UTF-8" }, "MultipartElements" -> { {"jpgFile", "file"} -> "test.jpg" } ] So this is another example. In this instance I am sending a text file and this appears to work.
testData = Import["test.txt","Text"]; URLExecute[ url, "Method" -> "POST", "Headers" -> { "Accept" -> "application/json; charset=UTF-8" }, "MultipartElements" -> { {"textData", "text/plain"} -> testData } ] From a Java point of view, the following actually works: https://stackoverflow.com/a/17174260/1167890
I would like not to be forced back into Java/MathLink if possible though.
Import["test.jpg","JPEG"]but I get errors. $\endgroup$image/jpeg, notfile. Try changing that. $\endgroup$The value {{jpgFile,image/jpeg}->Image[RawArray[Byte,<56,75,3>],Byte,<<1>>,<<12>>->True,MetaInformation->{Exif->{ImageWidth->4288,ImageLength->2848,BitsPerSample->{<<3>>},Make->NIKON CORPORATION,<<43>>,FocalLengthIn35mmFilm->34,SceneCaptureType->0,GainControl->1,<<5>>}}]} specified for the option MultipartElements is invalid.$\endgroup$