Comments (3)
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.
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.
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)
- Support for custom actions (on member and collection)
- Support for singular resources
- Fix the documentation HOT 1
- Reduce build size
- Option for automatic conversion of the json response to camel-case
- Weird behavior with update params HOT 1
- Resource name isn't getting converted from camelCase to snake_case HOT 1
- Wrong parsing when passing nested objects
- Identify error messages as rails ranger's errors HOT 1
- Support for inflections
- Interchangeable API adapters
- API calls fail for Rails apps that respond to HTML and JSON HOT 4
- Parameter substitution only seems to work for one parameter HOT 5
- Get method doesn't use existing resource HOT 7
- Deprecate the `transformData` option in favor of a better name
- Integrate with Rails authentication libraries
- this.client is undefined in readme example HOT 1
- Is request cancellation supported HOT 3
- Upgrade axios dependency to 0.21.1 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails-ranger.