New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Is there no way to remove a singe image with Multiple file uploads? #1704
Comments
Me too. Have you solve it? |
AFAIK its all or nothing... same thing with refile unfortunately. the joys of file uploading via the web |
Hi guys, any advance on this one? |
Yes, this is important for me, as well, thanks! - and I'm using jsonb as my datatype in postgresql.. |
I did answer my own question on SO: http://stackoverflow.com/questions/31381121/carrierwave-multiple-image-upload |
I learn from @lcx and use the following solution at my own project. def remove_image_at_index(index)
remain_images = @object.images # copy the array
deleted_image = remain_images.delete_at(index) # delete the target image
deleted_image.try(:remove!) # delete image from S3
@object.images = remain_images # re-assign back
end I wrote a blog post on this with a sample project. I hope this is helpful for other people. |
@bobintornado this delete another photo like i have 4 photos when i am going to delete 2 photo its delete 3 photo and this delete function work sometime not every time kindly need a proper solution. |
Is the bug reproducible?
|
@bobintornado Hi Bob, I have used your solution (https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Add-more-files-and-remove-single-file-when-using-default-multiple-file-uploads-feature) in my system. And I think there is a performance issue with it. For example, my Gallery model has 7 images, then I remove 1 one of them. I guess the code removes 1 image then reuploads and processes again 6 images. That takes a lot of time. It does that because I think when we re-assign back the new array of images to our Gallery model, it will treat that new array of 6 images as 6 new images not 6 old ones. Therefore, it does upload and process everything. Do you guys have any solution to add and remove one image in the array without reuploading images? |
Question is also asked on Stackoverflow http://stackoverflow.com/questions/40488123/carrierwave-multiple-images-upload-too-slow-when-adding-or-removing-images |
@anduong Yes there are quite some performance issues regarding this approach. How PostgreSQL handles array is one the reason I am aware of. This is by no means a sophisticated method of handling multiple images, and I suppose maybe you should consider writing some customised handling codes for this if performance becomes a concern. 😄 |
@bobintornado Thanks for your suggestion. I think the way CarrierWave handles multiple uploads with array type in database is so inflexible. Maybe extracting out another model (say Images) and using one-many or many-to-many relationship is a better way to go. By the way, how is your system performing? Is it slow when adding or removing images? |
@anduong I agree. Actually the first idea comes to me is the extraction of another model, too. Unfortunately I no longer monitor and responsible for the maintenance of the project where I developed this method for, so I am not sure about the performance situation. Another approach is stopping do it the rails way, separate the frontend and backend. For example, write a JS script for handling multiple images related UI and interactions, and handle the input in the backend however you'd like to. This way you have a much greater flexibility. 🤓 |
@bobintornado Couldn't agree with you more. My last project was not doing the Rails way (just using S3 direct upload) and it was much more flexible. |
I went for something more like this: @object.images[index].try(:remove!) # delete image from S3
@object['images'].delete_at(index) # remove from images array
@object.save
@object.reload # if you need to reference the new set of images |
I find out there is another way to do it with just params rails provided.
In ImagesController.rb
|
Closed by #2401. |
I'm using the master branch with the Multiple file upload feature, postgresql and have a model "products" with
I can store multiple images just fine, I can remove images with remove_images! but how can I remove just a single image?
Tried SO with no luck :(
http://stackoverflow.com/questions/31381121/carrierwave-multiple-image-upload
I looked at the mount_multiple_spec.rb and as far as I can see there is no way to remove a single image.
Please correct me if I'm wrong.
The text was updated successfully, but these errors were encountered: