Kenneth85
(Kenneth L. Jakobsen)
Novembro 14, 2016, 5:58pm
1
When i try to uploade a image with a user that is not a admin or moderator i get the success : “OK” insted of the image url. Hobe some one can help with a answer.
$.ajax({
url: "/uploads.json",
type: "post",
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-Token': getCsrftoken()
},
success: function (data) {},
error: function (XMLHttpRequest, textStatus, errorThrown) {}
});
1 curtida
Sure, @techapj will take a look and get back to you
techAPJ
(Arpit Jalan)
Novembro 15, 2016, 5:04am
3
Hi Kenneth,
I am not understanding what is the issue here.
I just verified that image upload works fine for both staff and non-staff users.
Kenneth85
(Kenneth L. Jakobsen)
Novembro 15, 2016, 7:23am
4
Hi
I am using the api with the synchronous true parameter to get the image url back with the responce. But this only works with admin and moderators and i cant find out why.
admin formdata send
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="username"
kenneth
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="type"
image/jpeg
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="file"; filename="Ballocity4.jpg"
Content-Type: image/jpeg
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="synchronous"
true
------WebKitFormBoundary6ez66C4lWix1aPev--
normal user
------WebKitFormBoundary1ntANOhhef17w01u
Content-Disposition: form-data; name="username"
Kenneth_Jakobsen
------WebKitFormBoundary1ntANOhhef17w01u
Content-Disposition: form-data; name="type"
image/jpeg
------WebKitFormBoundary1ntANOhhef17w01u
Content-Disposition: form-data; name="file"; filename="8589655248_7fe6db1efc_b.jpg"
Content-Type: image/jpeg
------WebKitFormBoundary1ntANOhhef17w01u
Content-Disposition: form-data; name="synchronous"
true
------WebKitFormBoundary1ntANOhhef17w01u--
Admin is working but not the normal one.
zogstrip
(Régis Hanol)
Novembro 15, 2016, 10:11am
5
Can you explain what you’re doing exactly? Why/how are you uploading images with “synchronous=true
”?
1 curtida
Kenneth85
(Kenneth L. Jakobsen)
Novembro 15, 2016, 12:09pm
6
Im creating a new editor for the company pleasecreate and are using the file upload api with the synchronous true parameter. When the image is uploaded i use the url from the response data in the post. The problem is that when a user that is not admin or moderator upload a image the response data only contains {“success”:“OK”}. and not the url. The code working for admin and moderators is shown below.
post request
$.ajax({
url: "/uploads.json",
type: "post",
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-Token': getCsrftoken()
},
success: function (data) {
var image = "<img src='" + data.url + "' width='" + data.width + "' height='" + data.height + "'/>";
},
error: function (XMLHttpRequest, textStatus, errorThrown) {}
});
formdata
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="username"
kenneth
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="type"
image/jpeg
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="file"; filename="Ballocity4.jpg"
Content-Type: image/jpeg
------WebKitFormBoundary6ez66C4lWix1aPev
Content-Disposition: form-data; name="synchronous"
true
------WebKitFormBoundary6ez66C4lWix1aPev--
RGJ
(Richard - Communiteq)
Novembro 16, 2016, 7:50pm
7
There is an explicit check in the code for staff users with regard to synchronous uploads. I don’t know why this is done but this is clearly the cause.
Why is the synchronous upload limited to staff users or API usage?
# frozen_string_literal: true
require "mini_mime"
class UploadsController < ApplicationController
include ExternalUploadHelpers
include SecureUploadEndpointHelpers
requires_login except: %i[show show_short _show_secure_deprecated show_secure]
skip_before_action :preload_json,
:check_xhr,
:redirect_to_login_if_required,
only: %i[show show_short _show_secure_deprecated show_secure]
protect_from_forgery except: :show
before_action :is_asset_path,
:apply_cdn_headers,
only: %i[show show_short _show_secure_deprecated show_secure]
before_action :external_store_check, only: %i[_show_secure_deprecated show_secure]
3 curtidas
sam
(Sam Saffron)
Novembro 16, 2016, 8:45pm
8
Its a security concern opening this up any wider, it would make it trivial exhaust unicorn workers really fast we opened this up.
6 curtidas
zogstrip
(Régis Hanol)
Novembro 16, 2016, 8:45pm
9
Since we might do a CPU-intensive process when images are uploaded, we have to ensure users don’t DDoS the instance by uploading lots of very large images.
Initially, synchronous mode was only available via the API. @eviltrout recently allowed staff members too when he added the wizard.
(ninja’d )
6 curtidas
Kenneth85
(Kenneth L. Jakobsen)
Novembro 17, 2016, 7:38am
10
hi thanks for the clarification and answer