# Image upload with synchronous true for new users

**URL:** https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886
**Category:** Support
**Created:** [Novembre 14, 2016, 5:58 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886 "2016-11-14T17:58:46Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Kenneth85](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kenneth85](https://meta.discourse.org/u/Kenneth85)
#### Post date: [Novembre 14, 2016, 5:58 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/1 "2016-11-14T17:58:46Z")

</div>

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) {}
});

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [Novembre 15, 2016, 12:52 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/2 "2016-11-15T00:52:17Z")

</div>

Sure, @techapj will take a look and get back to you

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [Novembre 15, 2016, 5:04 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/3 "2016-11-15T05:04:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kenneth85](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kenneth85](https://meta.discourse.org/u/Kenneth85)
#### Post date: [Novembre 15, 2016, 7:23 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/4 "2016-11-15T07:23:29Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [Novembre 15, 2016, 10:11 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/5 "2016-11-15T10:11:18Z")

</div>

Can you explain what you’re doing exactly? Why/how are you uploading images with “`synchronous=true`”?

---

<div class="post-metadata">

### Author: ![Kenneth85](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kenneth85](https://meta.discourse.org/u/Kenneth85)
#### Post date: [Novembre 15, 2016, 12:09 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/6 "2016-11-15T12:09:14Z")

</div>

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--

```

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [Novembre 16, 2016, 7:50 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/7 "2016-11-16T19:50:13Z")

</div>

> [@techAPJ](#):
>
> I just verified that image upload works fine for both staff and non-staff users.

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?

> <https://github.com/discourse/discourse/blob/main/app/controllers/uploads_controller.rb#L10>

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Novembre 16, 2016, 8:45 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/8 "2016-11-16T20:45:09Z")

</div>

> [@RGJ](#):
>
> Why is the synchronous upload limited to staff users or API usage?

Its a security concern opening this up any wider, it would make it trivial exhaust unicorn workers really fast we opened this up.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [Novembre 16, 2016, 8:45 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/9 "2016-11-16T20:45:21Z")

</div>

> [@RGJ](#):
>
> Why is the synchronous upload limited to staff users or API usage?

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_)

---

<div class="post-metadata">

### Author: ![Kenneth85](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@Kenneth85](https://meta.discourse.org/u/Kenneth85)
#### Post date: [Novembre 17, 2016, 7:38 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/10 "2016-11-17T07:38:24Z")

</div>

hi thanks for the clarification and answer

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [Mai 30, 2022, 10:00 UTC](https://meta.discourse.org/t/image-upload-with-synchronous-true-for-new-users/52886/13 "2022-05-30T10:00:11Z")

</div>


