Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix Scribd uploads with query parameters #3

Merged
merged 1 commit into from

2 participants

@daveworth

Scribd was returning 602, unknown file extension, for uploads. The problem was
that the URLs being uploaded (from S3) included AWS credentials as query
parameters. The doctype that rscribd, via calls from scribd-carrierwave,
extracted from http://<amazon_s3_host>/file.pdf?AWS_PARAMETERS=TRUE was
pdf?AWS_PARAMETERS=TRUE. By replicating the file extension extraction code
from rscribd and adding logic to remove the query parameters and passing this as
type to rscribd the error disappears.

Dave Worth Fix Scribd uploads with query parameters
Scribd was returning 602, unknown file extension, for uploads.  The problem was
that the URLs being uploaded (from S3) included AWS credentials as query
parameters.  The doctype that rscribd, via calls from scribd-carrierwave,
extracted from `http://<amazon_s3_host>/file.pdf?AWS_PARAMETERS=TRUE` was
`pdf?AWS_PARAMETERS=TRUE`.  By replicating the file extension extraction code
from rscribd and adding logic to remove the query parameters and passing this as
`type` to rscribd the error disappears.
45e0ec5
@aubreyrhodes aubreyrhodes merged commit e465050 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 18, 2012
  1. Fix Scribd uploads with query parameters

    Dave Worth authored
    Scribd was returning 602, unknown file extension, for uploads.  The problem was
    that the URLs being uploaded (from S3) included AWS credentials as query
    parameters.  The doctype that rscribd, via calls from scribd-carrierwave,
    extracted from `http://<amazon_s3_host>/file.pdf?AWS_PARAMETERS=TRUE` was
    `pdf?AWS_PARAMETERS=TRUE`.  By replicating the file extension extraction code
    from rscribd and adding logic to remove the query parameters and passing this as
    `type` to rscribd the error disappears.
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 1 deletion.
  1. +9 −1 lib/scribd-carrierwave.rb
  2. +6 −0 spec/scribd-carrierwave_spec.rb
View
10 lib/scribd-carrierwave.rb
@@ -11,7 +11,15 @@ def included(base)
end
def upload uploader
- args = { file: full_path(uploader), access: 'private' }
+ file_path = full_path(uploader)
+ args = { file: file_path, access: 'private' }
+
+ type = File.extname(file_path)
+ if type
+ type = type.gsub(/^\./, '').gsub(/\?.*$/, '')
+ args.merge!(type: type) if type != ''
+ end
+
scribd_user.upload(args)
end
View
6 spec/scribd-carrierwave_spec.rb
@@ -15,6 +15,12 @@
@scribd_user_mock.expects(:upload).with(has_entries(file: '/root/path/test_url', access: 'private'))
ScribdCarrierWave::upload @uploader
end
+
+ it "handles URLs with query parameters correctly" do
+ @uploader.stubs(:url).returns('http://example.com/file.pdf?AWSSTUFFBREAKS=TRUE')
+ @scribd_user_mock.expects(:upload).with(has_entries(type: 'pdf'))
+ ScribdCarrierWave::upload @uploader
+ end
end
describe "destroy" do
Something went wrong with that request. Please try again.