# File Upload POST format?

**URL:** <https://forums.knack.com/t/file-upload-post-format/9867>\
**Category:** API & Custom Code\
**Created:** [September 30, 2018, 2:14pm UTC](https://forums.knack.com/t/file-upload-post-format/9867 "2018-09-30T14:14:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulianSwal22288](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@JulianSwal22288](https://forums.knack.com/u/JulianSwal22288)\
**Post date:** [September 30, 2018, 2:14pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/1 "2018-09-30T14:14:34Z")

</div>

I'm trying to figure out what the files parameter should contain when uploading a file from a windows machine using the api...

I'm trying it with Postman to sort out the syntax..

I have this file name:   
C:\Users\Temp\Documents\Business\Test excel spreadsheet.xls

When I use:

@C:\Users\Temp\Documents\Business\Test excel spreadsheet.xls

I get:

{  
&nbsp;&nbsp;&nbsp; "errors": [  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "message": "Please select a file to upload."  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; ]  
}

So, any suggestions? I thought it was the spaces that may have been causing issues, but I tried a file without one, and it also give the same error..

Thanks

Julian

---

<div class="post-metadata">

**Author:** ![KevinLoh49942](https://avatars.discourse-cdn.com/v4/letter/k/ed655f/32.png) [@KevinLoh49942](https://forums.knack.com/u/KevinLoh49942)\
**Post date:** [August 10, 2020, 1:49am UTC](https://forums.knack.com/t/file-upload-post-format/9867/2 "2020-08-10T01:49:32Z")

</div>

Dear Greg, thanks for your reply. I still don't get how to use the api anyway ☹️. Wish that someone can guided me with an example of how to use the api..... I also don't quite understand the api call with below url.

[https://api.knack.com/v1/pages/](https://api.knack.com/v1/pages/) **scene\_key** /views/ **view\_key** /records

as from the documentation, the **scene\_key** need to change to scene\_252 in my case, and **view\_key** need to be view\_1625, so I need to write a javascript program in my site to call the value ? is that correct? I just can't call direct from browser right?

Sorry for my stupid questions again, I really don't have knowledge in javascript, I can only write a simple C# program.

---

<div class="post-metadata">

**Author:** ![GregGould73371](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@GregGould73371](https://forums.knack.com/u/GregGould73371)\
**Post date:** [August 9, 2020, 10:58pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/3 "2020-08-09T22:58:25Z")

</div>

Hi Kevin,

The assets URL is pointing to your S3 storage and not an API endpoint - it's not going to return anything without a complete file URL, which you get back from the API after you post a new file.

The ajax script can be in your API & Code \> JavaScript section or in a custom script file loaded on your site.

G

---

<div class="post-metadata">

**Author:** ![KevinLoh49942](https://avatars.discourse-cdn.com/v4/letter/k/ed655f/32.png) [@KevinLoh49942](https://forums.knack.com/u/KevinLoh49942)\
**Post date:** [August 9, 2020, 3:21pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/4 "2020-08-09T15:21:49Z")

</div>

I have 2 questions here......

1st....

I use my browser for "[https://api.knack.com/v1/applications/{YOUR-APP-ID}/assets/](https://api.knack.com/v1/applications/%7BYOUR-APP-ID%7D/assets/)" I get this error"

```
Cannot GET /v1/applications/5c5befdd0c5efd2cb80d6ff2/assets/"

2nd....
$.ajax({
   url: "[https://api.knack.com/v1/pages/{SCENE}/views/{VIEW}/records/](https://api.knack.com/v1/pages/%7BSCENE%7D/views/%7BVIEW%7D/records/)",
   type: "POST",
   data: {
      "field_123":"FILE_ID"
   },
   headers: {...},
   success: function (data) {
      // do something with new record data
   },
   error: function (xhr, ajaxOptions, thrownError) {
      // error
   }
});

all the codes above need to put in the knack api&code? sorry for my stupid questions as I'm very new in knack api. thanks for entertaining my questions.
```

---

<div class="post-metadata">

**Author:** ![GregGould73371](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@GregGould73371](https://forums.knack.com/u/GregGould73371)\
**Post date:** [July 29, 2019, 4:50pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/5 "2019-07-29T16:50:49Z")

</div>

Hi Stephen,

After the file is uploaded, use the "id" field from the returned data for the new file and send a POST request to the data object containing the file connection field to insert a record for the new file:

$.ajax({  
&nbsp; &nbsp;url: "[https://api.knack.com/v1/pages/{SCENE}/views/{VIEW}/records/](https://api.knack.com/v1/pages/%7BSCENE%7D/views/%7BVIEW%7D/records/)",  
&nbsp; &nbsp;type: "POST",  
&nbsp; &nbsp;data: {   
&nbsp; &nbsp; &nbsp; "field\_123":"FILE\_ID"  
&nbsp; &nbsp;},  
&nbsp; &nbsp;headers: {...},  
&nbsp; &nbsp;success: function (data) {  
&nbsp; &nbsp; &nbsp; // do something with new record data  
&nbsp; &nbsp;},  
&nbsp; &nbsp;error: function (xhr, ajaxOptions, thrownError) {  
&nbsp; &nbsp; &nbsp; // error  
&nbsp; &nbsp;}  
});

Hope this helps.

---

<div class="post-metadata">

**Author:** ![StephenChapman](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/stephenchapman/32/1759_2.png) [@StephenChapman](https://forums.knack.com/u/StephenChapman)\
**Post date:** [June 7, 2019, 5:26am UTC](https://forums.knack.com/t/file-upload-post-format/9867/6 "2019-06-07T05:26:03Z")

</div>

Hi Greg,  
I've got step one (uploading the file) working, but I'm struggling with step two, which is creating a new record in the object, and referencing the file ID. Do you have an example snippet?

---

<div class="post-metadata">

**Author:** ![GregGould73371](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@GregGould73371](https://forums.knack.com/u/GregGould73371)\
**Post date:** [February 25, 2019, 9:03pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/7 "2019-02-25T21:03:39Z")

</div>

Your S3 bucket for the project.&nbsp; [https://api.knack.com/v1/applications/{YOUR-APP-ID}/assets/](https://api.knack.com/v1/applications/%7BYOUR-APP-ID%7D/assets/)

---

<div class="post-metadata">

**Author:** ![vaibhavsha18338](https://avatars.discourse-cdn.com/v4/letter/v/7c8e57/32.png) [@vaibhavsha18338](https://forums.knack.com/u/vaibhavsha18338)\
**Post date:** [February 24, 2019, 3:14pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/8 "2019-02-24T15:14:04Z")

</div>

what is ASSETS\_URL

---

<div class="post-metadata">

**Author:** ![GregGould73371](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@GregGould73371](https://forums.knack.com/u/GregGould73371)\
**Post date:** [November 1, 2018, 3:49pm UTC](https://forums.knack.com/t/file-upload-post-format/9867/9 "2018-11-01T15:49:48Z")

</div>

Not sure what your using, but I have the following AJAX settings for JavaScript API file uploads...works fine.

...  
var file = document.getElementById(FILE\_INPUT\_ID).files[0];  
var form = new FormData();  
 form.append("files", file);

var settings = {  
&nbsp; "async": true,  
&nbsp; "crossDomain": true,  
&nbsp; "url": ASSETS\_URL + "file/upload",&nbsp; // change 'file' to 'image' if uploading images  
&nbsp; "method": "POST",  
&nbsp; "headers": KNACK\_HEADERS,  
&nbsp; "processData": false,  
&nbsp; "contentType": false,  
&nbsp; "mimeType": "multipart/form-data",  
&nbsp; "data": form,  
&nbsp; "success": function (data) {  
&nbsp; &nbsp; &nbsp;//..  
&nbsp; },  
&nbsp; "error": function(response) {  
&nbsp; &nbsp; &nbsp;//...  
&nbsp;}  
 }

$.ajax(settings).done(function (response) {&nbsp; // returns JSON with file details  
&nbsp; &nbsp;//...do something with response  
 });  
...
