Hello,
I’m trying to upload a video returned from media.captureVideo() to my server, although I can’t seem to find a way to get access to the video file directly. Is there anyway of doing this?
Thanks
Hello,
I’m trying to upload a video returned from media.captureVideo() to my server, although I can’t seem to find a way to get access to the video file directly. Is there anyway of doing this?
Thanks
You can download the file from the event.url with network.download to your documents directory.
Thanks for the reply, I didn’t realize network.download could be used that way.
Is there a special parameter I have to set for local files? i’m getting the following error:
ERROR: libcore.net.url.FileURLConnection cannot be cast to java.net.HttpURLConnection
The complete code:
local function downloadVideoTest(event) print (event.url) network.download( event.url, "GET", downloadVideoTestListen, "newUploadVideo.3gp" ) end media.captureVideo({listener = downloadVideoTest, preferredQuality = "low", preferredMaxDuration = 300})
Thanks again
You can’t upload a file to a server using the network.download() call…
There’s a lot of pieces of technology involved, not the least of which is your sever… (Read as - uploading / downloading user created photos/videos to a server from an app is not a trivial task).
The approach I think many have followed is the original multi-part form technique, first outlined here I think: http://developer.coronalabs.com/code/how-upload-image-server-multipartform-data
I’d imagine there’s a lot of forum posts about uploading files to a server (in general) as well. Best of luck.
Hello mpappas, thanks for the reply…
I’m not having any problems with uploading files to my server.
The problem i’m having is accessing the file generated from media.capureVideo. For example, with media.capturePhoto, I just save it to the temporary directory and then the app can access the file from there for uploading.
However with media.captureVideo, there is no option to save the video file to a different directory, and I can’t figure out a way of accessing the video file.
Any ideas?
Thanks again
OK, now I understand.
I wrote my own custom ios video capture stuff, so I don’t have code for accessing that side. But I am using the captureVideo() for android still - and I had trouble accessing the file… Looks like when recorded it’s not in the standard temp folder… So I wrote something like this to move it…
If I recall, ios creates something called “CapturedVideo.mov”, and I think that one was in a subfolder of the TemporaryDirectory… Print out the names (full path and all) of the captured file… And be prepared for the droid file to be placed in a slightly different location than ios…
[lua]
local function captureListener(event)
print("-- captureListener(event) called.")
print(" – event.url == ", event.url)
if( event.url ~= nil ) then – user didn’t cancel, right? (I think it comes back “” on cancel sometimes too?)
local sourcePath = string.sub(event.url,6,-1) – there’s a little garbage at the front of the path on android… something like “file:///” or something that chokes things…
local destPath = system.pathForFile( remoteName, system.TemporaryDirectory ) – remoteName decided somewhere else… MUST BE COMPLETE PATH (systemPathForFile)
print(" – s,d = “, sourcePath, destPath)
if ( utils.copyFile( sourcePath, destPath ) == true ) then – little utility function, copies to dest folder
print( " ---- video file successfuly copied to temp!”)
else
print( " ---->> video file copy FAILED!!")
end
end
end
[/lua]
Awesome, it worked perfectly…
I think the extra characters on the front of event.url must have tripped me up, I was assuming the video recorder was saving the file somewhere the app couldn’t access it.
Thanks for the help!
You can download the file from the event.url with network.download to your documents directory.
Thanks for the reply, I didn’t realize network.download could be used that way.
Is there a special parameter I have to set for local files? i’m getting the following error:
ERROR: libcore.net.url.FileURLConnection cannot be cast to java.net.HttpURLConnection
The complete code:
local function downloadVideoTest(event) print (event.url) network.download( event.url, "GET", downloadVideoTestListen, "newUploadVideo.3gp" ) end media.captureVideo({listener = downloadVideoTest, preferredQuality = "low", preferredMaxDuration = 300})
Thanks again
You can’t upload a file to a server using the network.download() call…
There’s a lot of pieces of technology involved, not the least of which is your sever… (Read as - uploading / downloading user created photos/videos to a server from an app is not a trivial task).
The approach I think many have followed is the original multi-part form technique, first outlined here I think: http://developer.coronalabs.com/code/how-upload-image-server-multipartform-data
I’d imagine there’s a lot of forum posts about uploading files to a server (in general) as well. Best of luck.
Hello mpappas, thanks for the reply…
I’m not having any problems with uploading files to my server.
The problem i’m having is accessing the file generated from media.capureVideo. For example, with media.capturePhoto, I just save it to the temporary directory and then the app can access the file from there for uploading.
However with media.captureVideo, there is no option to save the video file to a different directory, and I can’t figure out a way of accessing the video file.
Any ideas?
Thanks again
OK, now I understand.
I wrote my own custom ios video capture stuff, so I don’t have code for accessing that side. But I am using the captureVideo() for android still - and I had trouble accessing the file… Looks like when recorded it’s not in the standard temp folder… So I wrote something like this to move it…
If I recall, ios creates something called “CapturedVideo.mov”, and I think that one was in a subfolder of the TemporaryDirectory… Print out the names (full path and all) of the captured file… And be prepared for the droid file to be placed in a slightly different location than ios…
[lua]
local function captureListener(event)
print("-- captureListener(event) called.")
print(" – event.url == ", event.url)
if( event.url ~= nil ) then – user didn’t cancel, right? (I think it comes back “” on cancel sometimes too?)
local sourcePath = string.sub(event.url,6,-1) – there’s a little garbage at the front of the path on android… something like “file:///” or something that chokes things…
local destPath = system.pathForFile( remoteName, system.TemporaryDirectory ) – remoteName decided somewhere else… MUST BE COMPLETE PATH (systemPathForFile)
print(" – s,d = “, sourcePath, destPath)
if ( utils.copyFile( sourcePath, destPath ) == true ) then – little utility function, copies to dest folder
print( " ---- video file successfuly copied to temp!”)
else
print( " ---->> video file copy FAILED!!")
end
end
end
[/lua]
Awesome, it worked perfectly…
I think the extra characters on the front of event.url must have tripped me up, I was assuming the video recorder was saving the file somewhere the app couldn’t access it.
Thanks for the help!