Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Upload to Amazon S3
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01530635
Message ID:
01531106
Views:
84
>Brandon,
>
>That shouldn't be necessary. If you do:
>
>
>loHttp.AddPostKey("file","c:\temp\somefile.pdf",.T.)
>
Rick, just FYI:
I am doing AddPostKey("file","c:\temp\somefile.pdf",.T.)

and it definitely doesn't work with the filename="]+tcValue+[" in the cPostBuffer

Amazon replies with error message:
"Your POST request fields preceeding the upload file was too large"

If you drop the filename="]+tcValue+[" from the AddPostKey then Amazon accepts it fine.

I know that the filename="" is correct for a multi-part form post, so I'm not sure why Amazon S3 doesn't like it.


To not screw up the HTTP class I'm just adding a a 4th parameter
AddPostKey(tcKey, tcValue, llFileName, llToAmazonS3)

and dropping the filename="" when uploading to s3 only.




>
>it should do the FileToStr() conversion for you. You don't want to change that code - it definitely works. Otherwise that'll get blown away next time. The previous change I showed is integrated into the next rev of the tools.
>
>Regards,
>
>+++ Rick ---
>
>>Rick,
>>
>>Thanks, this got me even closer to a working solution. I had to make one other adjustment in the wwhttp.prg source
>>
>>I had to drop the filename="" from the addpostkey function
>>
>>
>>THIS.cPostBuffer = THIS.cPostBuffer + ;
>>            "--" + MULTIPART_BOUNDARY + CR + ;
>>            [Content-Disposition: form-data; name="]+tcKey+[" filename="] + tcValue + ["]+CR+CR+;
>>            FILETOSTR(tcValue) + CR
>>
>>
>>to
>>
>>
>>THIS.cPostBuffer = THIS.cPostBuffer + ;
>>            "--" + MULTIPART_BOUNDARY + CR + ;
>>            [Content-Disposition: form-data; name="]+tcKey+["]+CR+CR+;
>>            FILETOSTR(tcValue) + CR
>>
>>
>>>Do you have the source version? there's a bug that's snuck in a while back and it looks like you're hitting that.
>>>
>>>
>>>IF tnPostSize > 0
>>>   DO CASE
>>>      CASE !EMPTY(this.cContentType)
>>>		 	tcHeaders = "Content-Type: " + this.cContentType + CRLF + tcHeaders      
>>>      CASE THIS.nhttppostmode = 1
>>>         tcHeaders = "Content-Type: application/x-www-form-urlencoded"  + CRLF +;
>>>            IIF(!EMPTY(tcHeaders),CRLF+tcHeaders,"")
>>>      CASE THIS.nhttppostmode = 2
>>>         tcHeaders = "Content-Type: multipart/form-data; boundary=" + MULTIPART_BOUNDARY + CRLF + CRLF +;
>>>            IIF(EMPTY(tcHeaders),"",tcHeaders)
>>>
>>>         *** NOTE: extra dashes required to simulate browser operation!
>>>         lcPostBuffer = lcPostBuffer + "--" + MULTIPART_BOUNDARY + "--"  + CRLF
>>>         tnPostSize=LEN(lcPostBuffer)
>>>      OTHERWISE      && CASE THIS.nhttppostmode = 4  && XML or Raw
>>>         tcHeaders = "Content-Type: text/xml" + CRLF + tcHeaders		 
>>>   ENDCASE
>>>ELSE
>>>   tcHeaders =  IIF(!EMPTY(tcHeaders),tcHeaders,"")
>>>ENDIF
>>>
>>>
>>>(in the wwHttp::httpgetex method - just replace that block there's only a very small change)
>>>
>>>Basically the trailing -- were missing previously.
>>>
>>>This has come up in the last weeks a couple of times but what's odd is that I've had this set for years and I've been using to upload to a host of different servers.
>>>
>>>It's fixed, but not in any active release at this point. If you have source code you can make that change yourself. Otherwise I'll try to patch the existing versions.
>>>
>>>As always you get a faster response when you post on our message board as I'm not checking here every day.
>>>
>>>Aloha,
>>>
>>>
>>>+++ Rick ---
>>>
>>>>>You should use wwHttp to do this - wwIPStuff has been deprecated. Same syntax but separate object. Use the HttpGet() method which make your code simpler as well.
>>>>>
>>>>>
>>>>>Main issue is that you need to use multi-part form posting for uploading a file. loHttp.nHttpPostMode = 2 should address that. In addition I'm not sure you're sending the 'file' correctly.
>>>>>
>>>>>Here's an example from the help file:
>>>>>http://www.west-wind.com/webconnection/wwClient_docs?page=_0rs0twgr6.htm
>>>>
>>>>Thanks Rick, I'm getting much closer. Now the error message I get from S3 is The body of your POST request is not well-formed
>>>>
>>>>I'm using nhttppostmode=2
>>>>
>>>>Any ideas?
Brandon Harker
Sebae Data Solutions
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform