Multiple file upload in one request

You must Login before you can answer or comment on any questions.

Is this possible in Titanium Desktop? I've already implemented that in Adobe AIR and wondering to know if Titanium Desktop allows this too.

Thank you!

3 Answers

In mobile I think you can do it like this:

var appDataDir = Titanium.Filesystem.applicationDataDirectory;
var filename = appDataDir + "/sound.mp4";
var imageFile = Titanium.Filesystem.getFile(filename);
 
filename = appDataDir + "/sound2.mp4";
var imageFile2 = Titanium.Filesystem.getFile(filename);
 
var xhr = Titanium.Network.createHTTPClient();
xhr.open('POST', 'http://domain.com/', false);
xhr.send({      
    'media[]': imageFile.read(),
    'media[]': imageFile2.read()
});
It could possibly be used in Desktop.

— answered 3 years ago by Mattias Ahlström
answer permalink
1 Comment
  • What if user drag & drops files onto my app? How do I getFile? As my investigation showed, it allows only application related paths.

    — commented 3 years ago by Vadim Demedes

Having a related issue

SDK 1.6.2 iOS 4.3
I'm Developing with Appcelerator SDK 1.6.2 for iOS 4.3

I'm trying to upload multiple files to a server, the problem is the number of files is dynamic and therefore cant be predetermined in the params of the XHR send.

If I pass one file in it works fine but I cant seem to figure out how to pass in many.

I've tried creating an array to hold the media elements but no dice.

var media = [];
for(var i = 0; i < sync.images.length; i++){
     media[i] = Titanium.Filesystem.getFile(sync.images[i].path).read();
}
 
xhr.send({
    media: media // no workie
//  media: media[1] workie
});
I'm uncertain how to obtain this dynamically due to the fact that the number of images transferred can vary

Suggestions would be great

Not sure if this would help you or not... By try changing your code to this:

var media = [];
for(var i = 0; i < sync.images.length; i++){
     media[i] = Titanium.Filesystem.getFile(sync.images[i].path).read();
}
 
xhr.send({
    'media[]' media,
    'media[]': media[1]
});
When you are passing paramaters to the send function, for arrays I believe you have to use the [] bracket method next to the variable name. I changed your media to media[] if you didn't notice.

Hope it helps...

Your Answer

Think you can help? Login to answer this question!