I had the same problem like you have. My fault was, that i sent wrong headers in the gears request. Finally i came up with this working solution. Please note that im using ExtJS for the ui. So on file drop, i just fill a Ext.SimpleStore and on upload i loop through this store and upload each file with a Gears HTTPRequest. Hope this help you.
upload : function() {
if (this.store.getCount() === 0) {
return;
}
var dashdash = '--';
var crlf = '\r\n';
this.store.each(function(record) {
if (record.get('state') !== 'done') {
record.set('state', 'uploading');
record.commit();
var boundary = '------multipartformboundary' +
(new Date).getTime
();
var builder =
google.gears.factory.create('beta.blobbuilder');
var request =
google.gears.factory.create('beta.httprequest');
builder.append(dashdash);
builder.append(boundary);
builder.append(crlf);
builder.append('Content-Disposition: form-data;
name="user_file";
filename="' + record.data.fileName + '";');
builder.append(crlf);
builder.append('Content-Type:
application/octet-stream');
builder.append(crlf);
builder.append(crlf);
builder.append(record.data.blob);
builder.append(crlf);
builder.append(dashdash);
builder.append(boundary);
builder.append(dashdash);
builder.append(crlf);
request.onreadystatechange = function() {
switch(request.readyState) {
case 4:
if
(request.responseText) {
var res =
Ext.decode(request.responseText);
if (res &&
res.success == true) {
record.set('pctComplete', 100);
record.set('state', 'done');
} else {
record.set('pctComplete', 0);
record.set('state', 'error');
record.commit();
}
record.commit();
}
break;
}
}.createDelegate(this);
var url = window.system.getBackendUrl();
request.open("POST", url);
request.setRequestHeader('content-type',
'multipart/form-data;
boundary=' + boundary);
request.send(builder.getAsBlob());
}
}.createDelegate(this));
this.setButtonState();
},
