require "shrine"
require "shrine/storage/file_system"
require "shrine/storage/url"
Shrine.storages = {
cache: Shrine::Storage::Url.new(downloader: :wget),
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads/store"), # permanent
}var upload = null
var input = document.querySelector('input[type=file]')
var createFile = document.querySelector('#createFile')
if (createFile != null) {
createFile.addEventListener('click', startUpload)
function startUpload(){
var file = input.files[0]
console.log(file);
var options = {
endpoint: "http://localhost:3000/files/",
chunkSize: 5 * 1024 * 1024,
}
var upload = new tus.Upload(file, options)
upload.options.onProgress = function(bytesUploaded, bytesTotal) {
var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
console.log(bytesUploaded, bytesTotal, percentage + '%')
}
upload.options.onSuccess = function() {
var fileData = {
id: upload.url,
storage: "cache",
metadata: {
filename: upload.file.name.match(/[^\/\\]+$/)[0], // IE returns full path
size: upload.file.size,
mime_type: upload.file.type,
}
};
var hiddenInput = input.parentNode.querySelector("input[type=hidden]");
hiddenInput.value = JSON.stringify(fileData);
console.log(hiddenInput);
}
upload.start()
}
}
def create
@video = Video.new(video_params)
end
def video_params
params.require(:video).permit(:file, :file_data, :video_url)
end--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/74f62a72-d804-4219-ad88-ac9a5fa02142%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def create@video = Video.new(video_params)
In my application.js, the id in fileData is defined by : id:upload.url, but I use the hiddenInput with cached_attachment_data to store files and it need the id, not the url, it's why I wanted to use shrine_url.
Started POST "/videos" for 127.0.0.1 at 2017-10-04 16:37:45 +0200
Processing by VideosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ogc1/5+6sCYH6Xc9+GFkU+Vf8eSgbimWcRB1/7AVe32Xe62ff04e6FQohplB/11m8EIqNVRj0pu5SjY+eclMbQ==", "video"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x000000024adc40 @tempfile=#<Tempfile:/tmp/RackMultipart20171004-22706-1af97q.mp4>, @original_filename="TestVideo.mp4", @content_type="video/mp4", @headers="Content-Disposition: form-data; name=\"video[file]\"; filename=\"TestVideo.mp4\"\r\nContent-Type: video/mp4\r\n">}, "commit"=>"Submit"}
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `url' for #<ActionDispatch::Http::UploadedFile:0x000000024adc40>):
app/controllers/videos_controller.rb:28:in `create'
--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/5e126dfa-38cf-4b82-b37c-5813f9fa9080%40googlegroups.com.