Select to view content in your preferred language

Sending a reduced size image to file upload

4662
10
Jump to solution
11-15-2016 10:57 AM
TomSellsted
MVP Alum

Greetings,

I have a mobile app that I have built using the JSAPI that allows the user to take a picture with their iPad and posts it to a geoprocessing upload service.  This is working very well, but the image size is unnecessarily large.  I have a couple of functions that reduce the image size and create a BLOB that I would like to post to the same geoprocessing upload service.  I have tried many different variations of posting the file using the request module in the JSAPI with no luck.

The request I make gives me a request succeeded message, but I can see in my ArcGIS Server logs that the request is actually failing (which is also odd...).  The error message says "Error performing upload operation, File size or type not supported for this service".  I am using the FormData which the documentation says will work, but I am obviously missing something.  Here is a snippet of the code that I am using to post the reduced size image.

var data = new FormData();
data.append('file', imageResized);
var photoRequest = esriRequest({
   url: url,
   form: data,
   content: { f: "json" },
   handleAs: "blob",
   load: requestSucceeded, // callback
   error: requestFailed // on error
});

I would appreciate any suggestions on what I am missing. 

Thanks very much!

Regards,

Tom

0 Kudos
10 Replies
TomSellsted
MVP Alum

John,

Brilliant!  This was exactly what was missing.  The file uploaded quickly and was resized as expected.  I did use dojo domConstruct instead of put.  Here is the code that I used:

var formNode = domConstruct.create("form",{"method":"post","enctype":"multipart/form-data"});
var formData = new FormData(formNode);
formData.append("file",imageResized,filename);
‍‍‍

Thanks very much!  A great way to end my day!

Regards,

Tom

0 Kudos