image uploading in rhomobile - rhomobile

I tried image uploading in rhomobile. I choose picture from gallery of mobile and store in my application.My question is where the picture is stored after uploading?`

By default Rhomobile app has sqlite database
When you upload an image with the help of your model. it store the images name in blob format
enable :sync
property :image_uri, :blob
You can access the image by calling the blog_path of image_uri
<% #images.each do |obj| %>
<img src="<%=Rho::RhoApplication::get_blob_path(obj.image_uri)%>" width='300px' style="padding:10px"></img>
<% end %>

Related

Handle raise ActiveStorage::InvariableError after Deleting a file that uploaded with active storage

Hello i uploaded an image with active storage specificly an avatar for my model users, but after of upload this image, i delete this of the folder that contained the file. then, i have one attachment that exists without file.
i am checking user.avatar.blob (the user with the deleted file), and then this return null (with the console), i am try to handle this inside of a view but dont works, any advice for handle this exception?
<% unless !!user.avatar.blob.nil? || user.avatar.attached? %>
#this a simple avatar api that show for default
# an image when dont exist attachement or the file dont works or dont exist
<%= image_tag "https://avatars.dicebear.com/4.5/api/#{user.gender}/#{user.username}.svg?mood[]=happy&mood[]=happy", :size => "100x100" %>
<% else %>
<%= image_tag user.avatar.variant(
resize_to_limit: [100, 100]
)%>
<% end %>

Download File issue, CarrierWave upload

Thus far I have successfully set up CarrierWave so that it can upload many files including .pdf, .mp3, .wav, .mp4, and .mov. Awesome that's a pretty good success for me.
What I am trying to do now is to display those Uploads. On that display, I would like two links, one to download the uploaded file and the other to view the uploaded file. Currently, viewing the uploaded files works when I was attempting to create a way for the user to download the file.
Currently, here is the code that allows a user to view/listen/watch the uploaded file:
<% #user.uploads.each do |upload| %>
<tr>
<td><%= link_to upload.name, upload.attachment_url.to_s %></td>
<td class="right_align"><%= upload.to_a_date %></td>
<td class="right_align"><%#= upload.file_size %></td>
</tr>
<% end %>
Clicking on the link above allows a user to view the upload. How would I allow a user to download the same content? This gives me the correct path, but when I click on the link it views the file rather than downloads it.
I have also tried to do this in html5 with the following code:
<a href="#{upload.attachment_url.to_s}" download>Download</a>
This doesn't download the correct file.
Create separate action for this and use Rails send_file method:
def download_file
upload = Upload.find(params[:id])
send_file upload.attachment.url
end

Paper clip - stored image path inside active admin

All the files uploaded by paper clip are beeing stored inside public/system/images/pictures/ and lots of 000/000/002 folders and etc.
I Want to use image_tag inside one active admin's view to print all the images related to one gallery.
I can get the image object, and of course the image name, but how i figure out the right stored path?
Just call url on the image object, like this:
<% #gallery.images.each do |image| %>
<%= image_tag image.url %>
<% end %>

Only display a user-uploaded photo if it exists in rails

<%= image_tag message.photo.url(:small) %>
I have paperclip installed and the above code displays an image that the user uploads which has been resized to :small (in this case 40x40px. How can I get my page to display this image only if it exists? Currently if the message includes a photo that photo is displayed but all other messages show broken image links. Thanks
Paperclip adds the name of the attachment suffixed with a "?" to the attached model as a helper method to allow you to see whether or not there is an attachment. In your case, the helper method would be photo? on the message class. You could use it with the tertiary operator in this manner:
<%= message.photo? ? image_tag message.photo.url(:small) : "" %>
Or, if you'd like to show a default no-image image when there is no image...
<%= image_tag message.photo? ? message.photo.url(:small) : url_to_no-image_image %>
It's been a while since I've used rails, but wouldn't it suffice to just put in an if statement?

Rails PaperClip Attachments, knowing if there's a image thumbnail?

I'm using Rails 3 paperclip and allow users to upload attachments to the attachment model.
If the file is an image, the app generates image previews. If the file is not, it only uploads the file (no image previews).
Now I would like to display a list of all the attachments in the DB. So I use attachment.attachment(:large) and that works fine for image attachments, but errors (obviously) for non-image attachments.
What's a good way to check if it's an image attachment or not? If not, I'd like to display a standard static image. Any suggestions? thanks
This is what I did in my view:
<% if !(#attachment.attachment.content_type =~ /^image/).nil? %>
<%= image_tag #attachment.attachment.url(:small) %>
<%end%>
This assumes that your model is attachment, and my file, I so called attachment.
So you could do something like:
<% if !(#attachment.attachment.content_type =~ /^image/).nil? %>
<%= image_tag #attachment.attachment.url(:small) %>
<%else%>
<%= image_tag "/path/to/image/default.png" %>
<%end%>
Check attachment.attachment.attachment_content_type
For example, it might be: "image/jpeg"
You can create a migration that adds a attachment_content_type field of type string to your attachment table. When you create an attachment, paperclip stores the type of the file in that field. You can then check if the file type is something like "image/jpeg".
Maybe you could use default_url option? That would be shown if the real thumbnail doesn't exist.
http://www.suffix.be/blog/default-image-paperclp

Resources