Git Product home page Git Product logo

Comments (4)

pake007 avatar pake007 commented on June 5, 2024 2

hi @musixite Your code is working for aws-sdk-v1, since carrierwave-aws relies on aws-sdk v2, it is not working anymore. However, in v2, aws-sdk has a method :presigned_url defined in Aws::S3::Object, you can use this method to construct the direct download url for a s3 object:

s3 = Aws::S3::Resource.new
# YOUR-OBJECT-KEY should be the relative path of the object like 'uploads/user/logo/123/pic.png'
obj = s3.bucket('YOUR-BUCKET-NAME').object('YOUR-OBJECT-KEY')
url = obj.presined_url(:get, expires_in: 3600, response_content_disposition: "attachment; filename='FILENAME'")

from carrierwave-aws.

sorentwo avatar sorentwo commented on June 5, 2024

You don't get direct access to the S3 object, but you can add custom attributes to it with aws_read_options. This is something you can do for a particular uploader:

  configure do |config|
    config.aws_read_options = {
      content_disposition: 'attachment; filename='hardcoded_filename.mp3'
    }
  end

That will help with reading, but that still requires pulling the data down. Instead, you may want to set the content_disposition when writing the content. In that case, use:

  configure do |config|
    config.aws_write_options = {
      content_disposition: 'attachment'
    }
  end

Hope that helps!

from carrierwave-aws.

vincentcordel avatar vincentcordel commented on June 5, 2024

I tried to do what you mentioned but this doesn't change the fact that it copies the file first which takes 10-15sec to process. First option is not possible since I need to retrieve the filename from the database.

Still looking!

Thanks for your help,

  • Vincent

from carrierwave-aws.

sorentwo avatar sorentwo commented on June 5, 2024

If you write the header along with the content you can just use the generated url rather than copying the file locally. If you have to use read there is no way around downloading the file to the local server.

from carrierwave-aws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.