I uploaded image via paperclip so it's uploaded then after I will remove that image manually so now in our table entry is there that image is uploaded but in our system that image is not found. because we remove that image manually. In this case I want to display a default image if image is uploaded on server but not present in server.
My Image is stored in Amazon
Thanks In Advance.
Now, I Fix that issue by using following code
require "net/http"
url = URI.parse( image_path )
req = Net::HTTP.new(url.host, url.port)
begin
res = req.request_head(url.path)
rescue
end
Hope, This will help you in you feature
Related
I'm trying to submit form data and upload images from React Native app to CodeIgniter backend server. I'm choosing the images from react-native-image-crop-picker and only the data is sent and saved. But not the image is uploaded. I have tried this using Postman and it works perfectly.
I see that form.append() has 3 parameters. I checked the Postman request code, and it shows like this
data.append("attach_report", fileInput.files[0], "...3539240198157045_n.jpg");
My problem is, what's the datatype of fileInput.files[0] in this? Thanks in advance
Finally I found an answer for this. I have seen that the file returns from react-native-image-crop-picker is almost a File object. So I just edited the file like below.
// image is react-native-image-crop-picker returning file
image.uri = image.path;
image.name = "TEST.jpg";
image.type = image.mime;
image.dateModified = new Date();
Then,
const f = new FormData();
f.append('attach_report', image, image.uri);
f.append('user_id', 1);
Then submit the form. It works in my scenario...
I uploaded images to S3 with carrier wave gem.(Ruby on Rails, Vue.js)
But I want to reuse uploaded image as a file.
I have no idea about how to reuse uploaded S3 images as a file.
To be specific,
I made a model "reaction"
and the image is saved as a column of "reaction".
I can reuse image object like #reaction.image
(#reaction is a "reaction"`s object)
No trial
I totally dont know how to deal with it.
Once you get the image url from your table "Reaction". We can basically downloading an image located at a given URL and saved it as a file locally.
def download_aws_s3(url_aws_s3, filename)
uri = URI(url_aws_s3)
response = Net::HTTP.get_response(uri)
File.open(filename, 'wb'){|f| f.write(response.body)}
end
You can use "open-uri" or "down" gem as an alternative.
I'm using the Google Drive API where I can gain access to 2 pieces of data that I need to display a jpg file oin my program. WebViewLink is the "large" size image while thumbnailLink is the "thumb" smaller size of the same image.
I'm having an issue with downloading the WebViewLink that I do not have with the thumbnailLink. Part of my code calls either exif_imagetype($filename) or getimagesize($filename) so I can retrieve the type, height & width etc for the $filename. This is successful for the thumbnailView but not the WebViewLink...
code snippet...
$WebViewLink = "https://drive.google.com/a/treering.com/file/d/blablabla";
$type = exif_imagetype($WebViewLink);
--- results in the error
"PHP Warning: exif_imagetype(): stream does not support seeking..."
where as...
$thumbnailLink = "https://lh6.googleusercontent.com/blablabla";
$type = exif_imagetype($thumbnailLink);
--- successful
where $type = 2 // a .jpg file
Not sure what I need to do to gain a usable WebViewLink... maybe use the "export" function to copy to a file on my server that is accessible, then use that exported file for the functions that fail above?
Thanks for any help.
John
I think you are using the wrong property to get the image of the file.
WebViewLink
A link for opening the file in a relevant Google editor or viewer in a browser.
thumbnailLink
A short-lived link to the file's thumbnail, if available. Typically lasts on the order of hours.
You can try using the iconLink():
A static, unauthenticated link to the file's icon.
Sample image of thumbnailLink:
Sample image of a iconLink:
It will still show relevant image about the file.
Hope it helps!
I'm using carrierwave to upload images to s3 as an avatar for users, the image is been uploaded correctly, but when I try to update the user model I got an error if the url of uploaded image has a whitespace:
URI::InvalidURIError
bad URI(is not URI?): https://files.s3.amazonaws.com/avatar/110/111134a0-25d6-0130-f023-60eb69762222/photo copy.jpg
What is the better way to solve this?
I'm using carrierwave, fog, carrierwave_direct and rmagick to upload images.
[UPDATE:::::::::::::::::::::::::::::::::::::::::::::::::::::]
After reading this "carrierwave fails to load certain url" I added in AvatarUploader < CarrierWave::Uploader::Base :
def process_uri(uri)
URI.parse(URI.escape(URI.unescape(uri)))
end
But didn't work, It seems that this approach is correct, but keeps saving in the DB the url image with whitespace instead "%20".
Use URI.escape to clean up the URL before you validate it.
1.9.3p327 > URI.escape "https://files.s3.amazonaws.com/avatar/110/111134a0-25d6-0130-f023-60eb69762222/photo copy.jpg"
=> "https://files.s3.amazonaws.com/avatar/110/111134a0-25d6-0130-f023-60eb69762222/photo%20copy.jpg"
I have an ipad app that uses dropbox to sync images to the cloud so that i can access them with a webapp and process them etc etc.
the part i'm having trouble with is getting the file from dropbox to s3 via carrierwave. i have a photo model and i can create a new photo and upload and an image successfully. I can also put a file on dropbox. However when i try to get a file off of dropbox and put it on s3, the contents of the file is just text.
Are there some sort of mime types i need to set or something?
I am using dropbox_sdk and the get_file_and_metadata method. It returns me the file object successfully, but the contents are all just text. this is me hard coding the image file so i can be sure it exists..
dbsession = DropboxSession.deserialize(session[:dropbox_session])
#client = DropboxClient.new(dbsession, ACCESS_TYPE) #raise an exception if session not authorized
#info = #client.account_info # look up account information
#photo = Photo.new(params[:photo])
#db_image metadata = #client.get_file_and_metadata('/IMG_1575.jpg')
the part i don't know how to do is say take this image #db_image and use that file when creating a new photo and store it on S3.
I'm thinking it might be a 'mime type' issue, but i've read that that is only based on the file ext.
any insight you guys could share would really help me get past this hurdle. thanks!
Figured this out. Instead I used the direct_url.url method that is part of the dropbox-api gem used with the carrierwave gem. the direct_url.url method returns a secure full url path to that file that you can use as the remote_url value for carrierwave.
#client = Dropbox::API::Client.new(:token => 'derp', :secret => 'derp')
#dropbox_files = #client.ls "images/#{#event.keyword}/#{photo_size}/"
#dropbox_files.each do |f|
photo_exists = Photo.where(:dropbox_path => f.direct_url.url).count
if photo_exists == 0
#photo = Photo.create(:remote_filename_url => f.direct_url.url,
:dropbox_path => f.direct_url.url,
:event_id => #event.id)
end
end
Now, i'm pretty new at ruby, so i'll be posting a better way to step through the results, as that seems pretty slow and clunky.