2

我正在使用 Rhomobile API 使用相机拍摄照片。图像存储在 rhomobile 的 blob 文件夹中,路径存储在 rhom 中。

下面是我正在使用的代码,

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

我需要将图像文件复制到应用程序的基本文件夹中。谁能建议我在哪里以及如何实现这一目标。

提前致谢

4

1 回答 1

1

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.

于 2013-09-12T16:04:06.823 回答