Hello to all and especially Corona Staff!
I have spent a lot of time trying to upload photo to vk.com social network.
So, trouble in posting photo to users wall.
We should go through 4 steps to upload photo (http://vk.com/dev/upload_files?f=Uploading%20Photos%20on%20User%20Wall).
-
Getting uploading server URL. This works
-
Uploading photo to received server URL. Here is problem!
-
Saving photo to wall album. This will work surely
-
Posting to wall. This works (with message only, no photo)
Paragraph 2 in more details:
VK API says:
The application forms POST request for the received URL.
The request shall include photo field containing a file with an image (JPG, PNG, BMP or GIF)
I tried standard Corona method:
network.upload( postData.uploadUrl, "POST", networkListener, postData.postFile, postData.postDir, "multipart/form-data" )
Not working, because API wait POST with parameter named “photo”. How to put parameter name to this request?
Ok, I tried to go another way:
local headers = {} headers["Content-Type"] = "multipart/form-data" local path = system.pathForFile( postData.postFile, postData.postDir ) local file = io.open( path, "r" ) local len = file:seek( "end", 0 ) local imageData = file:read( "\*a" ) io.close(file) headers["Content-Length"] = len local params = {} params.headers = headers params.body = "photo="..imageData --and also tried "photo="..path network.request( postData.uploadUrl, "POST", networkListener, params)
And this also not works.
Extremely need help!!!
Thanks