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
PDF upload corrupted #52
Comments
What plugins are you using? Could you include your uploader, and mention any other plugins that you're globally loading? Also, are you using the latest version (1.3.0)? Because it looks like the PDF wasn't rewinded, and before 1.3.0 there were two bugs; one was that store_dimensions plugin wouldn't rewind the IO if it wasn't an image (but you probably don't have it loaded if you're uploading PDFs), other was that IO wasn't rewinded with determine_mime_type plugin when the |
Ah, sure. I'm on Shrine 1.2.0. I'll try updating and see if it's still an issue. # initializers/shrine.rb
require "shrine/storage/file_system"
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"),
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store"),
}
Shrine.plugin :activerecord
# image_uploader.rb
require "image_processing/mini_magick"
class ImageUploader < Shrine
MAX_IMAGE_SIZE_MB = 50
include ImageProcessing::MiniMagick
plugin :determine_mime_type
plugin :remove_attachment
plugin :store_dimensions
plugin :validation_helpers
plugin :versions, names: [:original, :thumb, :large]
plugin(:default_url) { |_| '/img/preview-not-available.jpg' }
Attacher.validate do
validate_max_size MAX_IMAGE_SIZE_MB.megabytes, message: "is too large (max is #{MAX_IMAGE_SIZE_MB} MB)"
validate_mime_type_inclusion ['image/jpeg', 'image/png', 'image/gif', 'application/pdf']
end
def process(io, context)
case context[:phase]
when :store
thumb = if io.mime_type == 'application/pdf'
with_minimagick(io.download) do |pdf|
# BUG: accessing `pdf` fails to open the file, presumably because it's corrupted
pdf.pages[0].resize("200x200")
end
else
resize_to_limit!(io.download, 200, 200)
end
large = resize_to_limit!(io.download, 800, 800)
{ original: io, thumb: thumb, large: large }
end
end
end |
Using 1.3.0 seems to have fixed the issue, thanks! Closing. |
Using Rails 4 and the ActiveRecord Shrine plugin, there seems to be file corruption in PDF uploads.
At some point between being a Rack file coming into Rails and the
process
method being called, the copy made by Shrine into the cache is being corrupted consistently.Filesizes
Original: 2520603
Shrine: 2520347
I've had a bit of trouble following the stacktrace to see at what exact point the
io
param ofprocess
copies the original Rack file to see what could be causing this, so if you know where please let me know and I can keep hunting. Thanks.File used: https://www.gnu.org/software/emacs/manual/pdf/emacs.pdf
The text was updated successfully, but these errors were encountered: