Reputation:
I'm using the Rhomobile API to capture photo using camera. The image is stored in blob folder of rhomobile and the path in rhom.
Below is the code i'm using,
def capture_image
options = { :enable_editing => false }
Camera::take_picture(url_for(:action => :callback_for_capture), options)
end
def callback_for_capture
photo_uri = @params['image_uri']
photo = Photo.create({
:id => generate_unique_id(),
:photo_uri => photo_uri
})
end
I need to copy the image file to my base folder of the application. Can anyone suggest me where and how can i achieve this.
Thanks in advance
Upvotes: 2
Views: 248
Reputation: 6544
You can use the file api along with ruby binread method, and copy the image from the blob folder to base folder.
Check this,
def callback_for_capture
photo_uri = @params['image_uri']
photo = Photo.create({
:id => generate_unique_id(),
:photo_uri => photo_uri
})
# Store the image file to base app path
file_name = photo_uri.to_s().split("/")[2]
file_blob_path = File.join(Rho::RhoApplication::get_blob_path(photo_uri))
file_content = File.binread(file_blob_path)
file_real_path = File.join(Rho::RhoApplication::get_base_app_path(), file_name)
f = File.new(file_real_path, "wb")
f.write(file_content)
f.close
end
More details over here http://ashiskumars.blogspot.in/2013/08/capturing-image-using-camera-api-uploading-to-server.html
Hope this helps you.
Upvotes: 1