rails-activestorage

How can i get url of my attachment stored in active storage in my rails controller

蓝咒 提交于 2020-05-14 18:09:05
问题 How can i get url of my has_one model attachment stored in active storage in my rails controller. So, that I would be able to send it as full link as api in json. So far, I have tried following methods but each of them are giving various issues: 1) current_user.image.service_url ---- undefined method `service_url' for # 2) Rails.application.routes.url_helpers.rails_disk_blob_path(current_user.image, only_path: true) , it gives me an output like: "/rails/blobs/%23%3CActiveStorage::Attached:

How can i get url of my attachment stored in active storage in my rails controller

六月ゝ 毕业季﹏ 提交于 2020-05-14 18:08:13
问题 How can i get url of my has_one model attachment stored in active storage in my rails controller. So, that I would be able to send it as full link as api in json. So far, I have tried following methods but each of them are giving various issues: 1) current_user.image.service_url ---- undefined method `service_url' for # 2) Rails.application.routes.url_helpers.rails_disk_blob_path(current_user.image, only_path: true) , it gives me an output like: "/rails/blobs/%23%3CActiveStorage::Attached:

Rails API ActiveStorage DirectUpload produce 422 Error InvalidAuthenticityToken

给你一囗甜甜゛ 提交于 2020-05-12 07:23:21
问题 I have a problem with Rails API app active storage. I have React from where i want to upload file. import React from "react"; import {DirectUpload} from "activestorage"; class SignIn extends React.Component { constructor(props) { super(props); this.state = { file: null }; this.handleFileChange = this.handleFileChange.bind(this); this.handleFileSubmit = this.handleFileSubmit.bind(this); } handleFileChange(e){ this.setState({file: e.target.files[0]}) } handleFileSubmit(){ const upload = new

Rails API ActiveStorage DirectUpload produce 422 Error InvalidAuthenticityToken

微笑、不失礼 提交于 2020-05-12 07:22:33
问题 I have a problem with Rails API app active storage. I have React from where i want to upload file. import React from "react"; import {DirectUpload} from "activestorage"; class SignIn extends React.Component { constructor(props) { super(props); this.state = { file: null }; this.handleFileChange = this.handleFileChange.bind(this); this.handleFileSubmit = this.handleFileSubmit.bind(this); } handleFileChange(e){ this.setState({file: e.target.files[0]}) } handleFileSubmit(){ const upload = new

How to attach Base64 image to Active Storage object?

淺唱寂寞╮ 提交于 2020-04-17 17:54:53
问题 I can attach a png image from disc by and everything works just fine: obj.attachment.attach( io: File.open('dog.png'), filename: "image_name", content_type: "image/png" ) But it doesn't work giving result like too tiny empty square when I save a Base64 png image which encoded into String something like that "data:image/png;base64,iVB**..REST OF DATA..**kSuQmCC" by: obj.attachment.attach( io: StringIO.new(encoded_base_sixty_four_img), filename: "image_name", content_type: "image/png" ) Also I

Rails 5.2 Active Storage direct upload failure: CORS header ‘Access-Control-Allow-Origin’ missing

牧云@^-^@ 提交于 2020-04-13 02:55:51
问题 I am trying out Rail 5.2.0.rc1 Active Storage, using its included JavaScript library to upload PDF docs directly from the client to the cloud. But on submitting a form I get a browser error in both Firefox & Chrome: Cross-Origin Request Blocked... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Headers are set thus this.xhr.setRequestHeader... in the activestorage.js and dont appear to be configurable: https://github.com/rails/rails/blob/master/activestorage/app/javascript

Change ActiveStorage DirectDisk service configuration at runtime

你。 提交于 2020-03-25 13:03:13
问题 I am using Rails 5.2 and ActiveStorage 5.2.3 and DirectDiskService. In order to have user uploads grouped nicely in directories and in order to be able to use CDNs as I please (eg CloudFlare or CloudFront or any other), I am trying to set up a method in ApplicationController that sets the (local) path for uploads, something like: class ApplicationController < ActionController::Base before_action :set_uploads_path # ... private def set_upload_paths # this doesn't work ActiveStorage::Service:

Secure active storage with devise

ε祈祈猫儿з 提交于 2020-03-17 06:02:23
问题 Using devise gem to authenticate all users of an application. I'm trying to implement Active Storage. Let's say that all users must be authenticated as soon as they reach the app: class ApplicationController < ActionController::Base before_action :authenticate_user! ... end How to secure the Active Storage generated routes? URL of an uploaded file can be accessed without having to authenticate first. The unauthenticated user can get the file url generated by Active Storage. 回答1: This is not a

How do you change the Active Storage Service url_expires_in timeout?

北慕城南 提交于 2020-02-19 10:16:39
问题 When Active Storage creates a signed variant URL, it sets a default timeout of 5.minutes . I really want to increase this, but I've been trawling Github issues, code diving and cannot find it anywhere. On line 44 of the services class a class_attribute is set, but how can this be overwritten? https://github.com/rails/rails/blob/5-2-stable/activestorage/lib/active_storage/service.rb#L44 I'm using url_for to generate the signed variant links and there doesn't seem to be anyway to change the

Getting filename before saving in ActiveStorage - Rails 5.2.1

拈花ヽ惹草 提交于 2020-01-25 08:42:25
问题 I am trying to get the name of the file uploaded by a user before ActiveStorage goes on to save it. The form is generated using form_with and is shown below: <%= form_with model: upload do |form| %> <div class=""> <%= form.file_field :files, multiple: true, direct_upload: true, required: true %> <%= form.label :files, '', class: 'icon ion-ios-cloud-upload' do %> <span>click the icon to select files</span> <% end %> <div class="actions"> <%= form.submit "Upload", class: "btn btn-primary" %> <