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
>
>