This might get you closer to your goal if you want to check it out. I haven’t gotten the multipart form upload part to work, but the image is being saved to the sandbox ok and is ready to be uploaded:
[lua]
local photo – holds the photo object
local PHOTO_FUNCTION = media.PhotoLibrary – or media.SavedPhotosAlbum?
local tmpDirectory = system.TemporaryDirectory
local photoGroup
local localPhotoFileName=“test.jpg”
local btn_selectFromGallery
– prepare the image for upload by saving it to the sandbox temporary directory
local function prepImageForUpload()
print( “saving”…localPhotoFileName )
--save the image to the local app sandbox
display.save(photoGroup, localPhotoFileName, tmpDirectory)
print( “pic saved in temp directory, uploading now” )
--finally upload the pic
uploadPic()-- this would be your custom local function, needs work
end
– Executes after the user selects a pic from the gallery (or cancels)
local handleDoneSelectingPic= function(event)
photo = event.target
print(“done selecting pic”)
if photo then
print( “picSelected” )
photoGroup = display.newGroup()
--this shows it on the screen too
photoGroup:insert(photo)
photoGroup:scale(.3,.3)
photoGroup.x = display.contentWidth/2
photoGroup.y = display.contentWidth/2-100
localPhotoFileName=“photoSelected”…math.random(100000, 999999)…".jpg"
--save image after delay so that not in gallery picker and it has time to actually be rendered on the screen
timer.performWithDelay( 500, prepImageForUpload )
else
print( “No Image Selected” )
end
end
– btn handler that opens the gallery
local btn_selectFromGallery
local function selectFromGalleryBtn_handler( event )
– Delay a bit to allow the display to display refresh before calling the Photo Picker, then open it
timer.performWithDelay( 100, function() media.selectPhoto( { listener = handleDoneSelectingPic, mediaSource = PHOTO_FUNCTION } ) end )
return true
end
— just the selectFromGallery button
btn_selectFromGallery=display.newImage(“images/btn_uploadPics.png”,centerX,450)
btn_selectFromGallery:addEventListener(“tap”, selectFromGalleryBtn_handler)
sceneGroup:insert(btn_selectFromGallery)
[/lua]