[英]Rails, Active Storage, MiniMagick - convert PDF pages to images (.png, .jpg, etc.) and upload to active storage
[英]upload a file(.pdf, .jpg etc) using rails active storage via API through postman? (not through rails views)
我看到了N个关于使用rails view将文件上传到本地活动存储、S3 等的教程。 But I cannot find a legit source on how to upload a file to an active storage through API Say via postman, like what are prerequisites required to pass an attachment through API via postman?
让我详细说明一下。
第1步:通过React或任何前端框架,我将选择一个文件上传(a.PDF文件),最终它应该保存在某个地方。
第 2 步:这个选择的文件应该作为 API 传递到后端服务,在该后端服务中,选择的文件的存储将保存在 AWS S3 等存储中。
如何发送 API 请求来存储文件? 有人可以帮我解决吗?
打开 Postman 非常简单
Go 到 Body -> Form-data 然后将鼠标移到关键字段,您将找到 File Option
Or send the File Path in the raw JSON object as well like this and then Create the Object at backend so place check on file object if it blank then send path like this
// For Temporary Use Over Back End Only NOT NEED To Send These
"file_path" : "/home/jolly/Downloads/pdf/pdf-5.pdf",
"file_name" : "pdf-5.pdf"
然后在代码中使用它来创建文件 object ,您将其传递到您需要保存 s3 或 rails 存储的位置
file_path = params[:file_path]
file_name = params[:file_name]
image_path = Rails.root+file_path
image_file = File.new(image_path)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.