You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
I have a bit of a special custom processor. It uses a conversion micro service written in house. Things get funky when I try to return the converted file after downloading it. Below is my non functional processor.
module Paperclip
class Convertion < Processor
def initialize(file, options = {}, attachment = nil)
super
@file = file
@format = options[:format]
@basename = File.basename(@file.path, File.extname(@file.path))
end
# Main method for the processor, reference :
# https://github.com/thoughtbot/paperclip#custom-attachment-processors
#
# @return [File] The processed file
def make
converted = RestClient::Request.execute(
method: :post,
url: 'http://localhost:5678/foobar',
payload: {
format: @format,
file: @file
},
raw_response: true)
return_file = Tempfile.new([@basename, @target_format])
return_file.binmode
converted.file.open
return_file.write(converted.file.read)
return_file
end
end
end
On upload, this processor fails with a Closed Stream error, caused by a file.rewind.
If I comment out the rewind in s3.rb at line 392, everything works fine and the upload completes properly. Interestingly too, if I modify my processor for testing with the following, it works too (the file passed as an argument to open is the same file generated by the micro-service). The problem seems to happen only when I download a file form my service.
module Paperclip
class Convertion < Processor
def initialize(file, options = {}, attachment = nil)
super
@file = file
@target_format = options[:format]
@basename = File.basename(@file.path, File.extname(@file.path))
end
# Main method for the processor, reference :
# https://github.com/thoughtbot/paperclip#custom-attachment-processors
#
# @return [File] The processed file
return_file = Tempfile.new([@basename, @target_format])
return_file.binmode
return_file.write(open("/Users/foobar/Downloads/1024.png").read)
return_file
end
end
end
So... the questions are :
Is this file.rewind in s3.rb at line 392 really necessary ? I am unsure on why it has been placed in there.
Why do you think the files created through a download are closed but not the ones created through a local open. FYI, i have tried the second piece of code with multiple files with both open getting a local and a remote file with always the local files working and remote ones bugging.
The text was updated successfully, but these errors were encountered:
So after further investigation, I have found my issue. I am still unsure on why it caused the problem but I will share just in case someone has the same issue.
Ruby : 2.3.0
Rails : 5.1.4
Paperclip : 6.0.0
AWS-SDK : 3.0.1
I have a bit of a special custom processor. It uses a conversion micro service written in house. Things get funky when I try to return the converted file after downloading it. Below is my non functional processor.
On upload, this processor fails with a Closed Stream error, caused by a file.rewind.
If I comment out the rewind in s3.rb at line 392, everything works fine and the upload completes properly. Interestingly too, if I modify my processor for testing with the following, it works too (the file passed as an argument to open is the same file generated by the micro-service). The problem seems to happen only when I download a file form my service.
So... the questions are :
Is this file.rewind in s3.rb at line 392 really necessary ? I am unsure on why it has been placed in there.
Why do you think the files created through a download are closed but not the ones created through a local open. FYI, i have tried the second piece of code with multiple files with both open getting a local and a remote file with always the local files working and remote ones bugging.
The text was updated successfully, but these errors were encountered: