Coder Social home page Coder Social logo

Comments (3)

ryanmk54 avatar ryanmk54 commented on July 21, 2024 1

I don't think ActiveStorage work for this situation because files may need to be uploaded to a different directory on disk based on the class name. With ActiveStorage, files have a single root directory. Shrine allows uploading files to different directories, but it is more complicated than using Ruby's File.open method. I agree that asynchronous uploads are better for performance, but I'll wait to let the other team member decide if he wants to use Shrine or upload the file directly.

from rails-ranger.

ryanmk54 avatar ryanmk54 commented on July 21, 2024

Here is what I tried with rails-ranger

import RailsRanger from 'rails-ranger'

const config = {
  axios: {
    baseURL: '/merchandising',
    headers: {
      'Content-Type': 'multipart/form-data',
      'Accept': 'multipart/form-data'
    }
  }
};

export default new RailsRanger(config);

// FDapi is for form-data api
FDapi.post('shelf_tag_templates/upload_image', fd,
{headers: {
  'Content-Type': 'multipart/form-data',
  'Accept': 'multipart/form-data'
}})

Rails server log:

Parameters: {"{}"=>nil}

Here is what works with Axios

import axios from 'axios';
axios.post('/merchandising/shelf_tag_templates/upload_image', fd,
{headers: {
  'Content-Type': 'multipart/form-data',
  'Accept': 'multipart/form-data'
}})

Rails server log:

Parameters: {"custom_file"=>#<ActionDispatch::Http::UploadedFile:0x00007fc8000e7c78 @tempfile=#<Tempfile:/tmp/RackMultipart20201125-27867-1ml5lx0.gif>, @original_filename="amazed.g
if", @content_type="image/gif", @headers="Content-Disposition: form-data; name=\"custom_file\"; filename=\"amazed.gif\"\r\nContent-Type: image/gif\r\n">}

from rails-ranger.

victor-am avatar victor-am commented on July 21, 2024

Hmmmm, I never considered the file transfer scenario for the library 🤔
In fact I would suggest a different approach instead:

Usually uploading files into the rails server is not a good idea because, among other issues, it will lock the request thread/process for a long time, increasing the overall response time of the application.

If it suits your scenario you could try asynchronous upload (in which the user uploads the file to S3/Azure/etc via js and then it only sends a link string to rails server to keep track of).

More info in the Active Storage docs: https://guides.rubyonrails.org/v5.2.0/active_storage_overview.html


However, if the solution above doesn't fit your needs I will have to test around a bit to see if there is something that can be done or if it should be implemented as a new feature 🤔

from rails-ranger.

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.