I had the same problems like you have. My FILES Array was empty but
the content was delivered in the POST Array.
My fault was, that i sent wrong headers. My finally working solution
is this, wich fills the files array:
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);
/* Mark end of the request. */
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);
/* Use Gears to submit the data. */
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();
},
Please note, that im using ExtJS for the UI and on file drop, i just
fill an Ext.SimpleStore with the filedata and files blob. In my upload
function i loop through this store and upload each file with gears...
Hope this help ;)
On 2 Okt., 22:35, István Miklós Antal <[email protected]> wrote:
> This partially works but for some reason, PHP doesn't understand it
> correctly, instead of the $_FILES, the $_POST gets populated like
> this:
>
> array('fileFormat\\"-----------------------------870375749853' =>
> '.....file contents here')
>
> For some reason PHP thinks that this is a simple POST variable and
> doesn't treat it as a file.
>
> On Sep 28, 4:22 pm, Željko Mitrović <[email protected]> wrote:
>
> > Hope this would help. Assuming that you have files data in
> > gearsUploadedFiles array and URL in myUrl this should emulate classic form
> > upload:
>
> > var randomNumber = Math.floor(Math.random() * 1000000000000);
> > var boundary = "---------------------------" + randomNumber;
> > var dashDash = '--';
> > var crlf = '\r\n';
> > var dashDashBoundaryCrlf = dashDash + boundary + crlf;
>
> > var builder = google.gears.factory.create('beta.blobbuilder');
>
> > builder.append(dashDashBoundaryCrlf);
> > builder.append('Content-Disposition: form-data; name="fileFormat"');
> > builder.append(crlf);
> > builder.append(dashDash);
> > builder.append(boundary);
>
> > var item = 0;
> > while (gearsUploadedFiles[item]) {
> > builder.append(crlf);
> > var name = gearsUploadedFiles[item].columnId;
> > builder.append('Content-Disposition: form-data; name="' + name + '"');
> > if (gearsUploadedFiles[item].name) {
> > builder.append('; filename="' + gearsUploadedFiles[item].name +
> > '"');
> > }
> > builder.append(crlf);
> > builder.append('Content-Type: application/octet-stream');
> > builder.append(crlf);
> > builder.append(crlf);
> > builder.append(gearsUploadedFiles[item].blob);
> > builder.append(crlf);
> > builder.append(dashDash);
> > builder.append(boundary);
> > item++
>
> > }
>
> > builder.append(crlf);
> > // YOU CAN ADD ADITIONAL CONTET HERE IF NEEDED
> > builder.append(crlf);
> > builder.append(dashDash);
> > builder.append(boundary);
>
> > builder.append(dashDash);
> > builder.append(crlf);
>
> > gearsHttpRequest = google.gears.factory.create('beta.httprequest');
>
> > gearsHttpRequest.onreadystatechange = function(){
> > if (gearsHttpRequest.readyState == 1) {
> > // ACTION ON UPLOAD START
> > }
> > if (gearsHttpRequest.readyState == 4) {
> > if (gearsHttpRequest.status == 200) {
> > //ACTION IF SUCCESS
> > }
> > else {
> > // ACTION IF FAILURE
> > }
> > }
>
> > };
>
> > gearsHttpRequest.open('POST', myUrl);
> > gearsHttpRequest.setRequestHeader('content-type',
> > 'multipart/form-data;boundary=' + boundary);
>
> > gearsHttpRequest.send(builder.getAsBlob());
>
> > ---
> > Željkohttp://skitanja.blogspot.com/
>
> > "you can't stay young forever...
> > but you can be immature for the rest of your life"
> > Unknown
>
> > 2009/9/26 István Miklós Antal <[email protected]>
>
> > > Hello,
>
> > > I have searched over a day now, but I still can't find a good solution
> > > to post my blobs from my local storage to a remote server. I only
> > > found ones that partially worked. Can somebody post me a good example
> > > that would help me understand how to do this?
>
> > > I am using PHP server side, so the best solution would be something
> > > that could send data that would populate the $_FILES and the $_POST
> > > (send supplementary data with the file), but of course any other
> > > working solution would be good.
>
> > > Thank you in advance,
> > > István