Net::ReadTimeout for avatar uploader
Ashviniv opened this issue · 3 comments
I have uploaded base64 data to carrierwave using carrierwave-base64.
When I upload this as image, I send email with this uploaded file as attachment. I have used following line to send it as attachment.
attachments[File.basename(model.avatar.url)] = open(model.avatar.url) {|f| f.read}
I am getting Net::ReadTimeout Error
.How do I reduce the time to read this file?.How do I handle this situation?
To answer your question i need more details.
Where are you persisting the image, and send out the email? Is is all done in a single controller action?
Storing image on amazon-s3. And I am saving the image and sending out an email in the same controller. The email attachment is set in mailer model.i.e the above line I shared is in mailer model.The controller action is:
def update
@user = User.find(params[:id])
UserMailer.profile_picture_mail(@user).deliver if user.update_attributes(avatar: params[:user][:image_data])
end
In the mailer:
def profile_picture_mail(user)
@user = user
attachments[File.basename(user.avatar.url)] = open(user.avatar.url) {|f| f.read}
mail(:to => 'abc@gmail.com',:subject => "Profile picture")
end
So the problem here is not in the gem.
It is just to much work for one request. I would suggest you to keep the upload processing in the controller action, and move email sending to the async job.