Comments (16)
Planning to work on this in this weekend.
from carrierwave-base64.
@ehannes the parameters look fine. I will take a look at the issue, if I will find time on this weekend
from carrierwave-base64.
actually this should work already, if you defined content_type_whitelist
in your uploader
from carrierwave-base64.
I tried it, but I didn't get it to work. I declared it as following in my uploader:
def content_type_whitelist
%w(pdf/application)
end
and then uploading a pdf file, but it was rejected due to incorrect content type. Then I thought it had something to do with the base64 conversion.
from carrierwave-base64.
I'm having the same issue. Using this in my Uploader.
def content_type_whitelist
/image\//
end
Is there any status on this?
from carrierwave-base64.
Issue won't reproduce with current version of gem (2.5.3 at the moment) and carrierwave v1.1.0, tested with rails 5.1 and 4.2.8
from carrierwave-base64.
@bobishh Dis you set the content_type_whitelist
to an array of extensions? I think it did not work for @ehannes and @jflewis because they tried to use MIME types for the whitelist
from carrierwave-base64.
I've tried both ways - regex and array (except not with pdf but with image/png and image/jpeg), and it worked in all cases ¯_(ツ)_/¯
from carrierwave-base64.
@bobishh okey, thank you, I'm closing this issue then
from carrierwave-base64.
Great! If I have the time to check I will let you know if I can solve this issue by upgrading the gems.
from carrierwave-base64.
@bobishh @lebedev-yury I still fail to get this to work. I guess I'm doing some stupid mistake... I had a look at the readme for the ContentTypeWhitelist
module in CarrierWave and if I understand it correctly, I would be able to write something like this:
def content_type_whitelist
%w(application/pdf image/jpg image/jpeg image/png)
end
If I add the above code and then try to attach a pdf file to the attachment, it fail with the following error: en.errors.messages.content_type_whitelist_error
. If I remove the content_type_whitelist
method from my uploader, I can once again attach pdf files.
from carrierwave-base64.
I have solved the mystery. I tried in the console and it worked. Then I thought maybe something is wrong with my tests, and I were correct. Before I added the file with Rack::Test::UploadedFile.new(file_path)
. If I tried a simple File.open(file_path)
it worked. Rack::Test::UploadedFile is for attaching files to a request (http://www.rubydoc.info/gems/rack-test/0.5.5/Rack/Test/UploadedFile) and I was attaching a file to a model. Sorry for the trouble! I hope this can help others with the same problem.
from carrierwave-base64.
Sorry to bother you again but now when I tried a real upload, it still doesn't work, (though my tests are now working). I guess that means that the error is in the frontend. I'll have to continue my research... I'll be back if I get it to work. If someone wants to look at it, this is my parameters sent to the controller:
Parameters: {"profile"=>{..., "attachment"=>"data:application/pdf;base64,JVBERi0xLjQKJc...
This is the error I get:
en.errors.messages.content_type_whitelist_error
This is my content_type_whitelist:
def content_type_whitelist
%w(application/pdf image/jpeg image/png)
end
from carrierwave-base64.
@ehannes did you figure out what was going on or how to figure out the file name the whitelist is checking against?
Have a similar issue where I'm getting the error:
You are not allowed to upload "" files, allowed types: image/jpg, image/jpeg, image/png",
so it's stripping out the mime type somewhere and leaving it blank - would love some troubleshooting help if you figured out how to access the file name for a base64 uploaded file.
My JSON file being submitted:
{id: 2057, image: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD…du8xO+QR825cZHToMAVmNPNM52KFBHTPHHuaPNmiTWh//2Q==", image_filename: "ABCD_1.jpg"}
Wondering if this is impacted by changing my photo.rb file to use image_filename to populate the filename
Photo.rb
mount_base64_uploader :image, ImageUploader, file_name: -> (u) { u.image_filename }
from carrierwave-base64.
@goelinsights No, actually I have not fixed this yet...
from carrierwave-base64.
alternative to validate content_type :
Add in gemfile :
gem 'cocaine', '~> 0.5.8'
gem 'file_validators'
Add in model :
validates :img, file_size: { in: 100.bytes..1.megabyte }, file_content_type: { allow: ['image/jpeg', 'image/png', 'image/jpg'], mode: :strict }
from carrierwave-base64.
Related Issues (20)
- Error: "ArgumentError : wrong number of arguments (given 1, expected 0)" HOT 4
- Avatar is not saving into database HOT 1
- Have to reload AR model when saving base64 photos. HOT 5
- Regression on 2.6.0 when passing base64 string HOT 5
- Support for multiple uploads ? HOT 4
- Permission denied @ unlink_internal - E:/project_name/public/uploads/1515432095-16344-0028-5553/video.mp4 HOT 1
- uninitialized constant CarrierWave::Mount (NameError) HOT 1
- "mount_base_64_uploader" method not recognized from rails console HOT 3
- issue with cloudinary gem integration HOT 1
- Validation fails on :file attribute HOT 4
- NoMethodError undefined method _will_change HOT 1
- Not able to nullify file field in 2.8.0 HOT 2
- When i supply base64 string it works but during update when the string is from the s3 image sets to nil HOT 2
- Wrong data format for automatic detection. `.ai`instead of `.pdf` HOT 3
- Save as JPG instead of PNG HOT 1
- Not working for multiple file upload HOT 1
- try to use carrierwave-base64 with nobrainer HOT 4
- depending on mimemagic, licensing problem with GPL HOT 13
- mimemagic dependency HOT 1
- NameError (uninitialized constant CarrierWave::MiniMagick::ImageProcessing):
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carrierwave-base64.