# How to upload a file using custom script?

**URL:** <https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228>\
**Category:** Server-Side Scripting\
**Created:** [June 27, 2015, 11:02am UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228 "2015-06-27T11:02:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhijit\_Nair](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Abhijit\_Nair](https://community.dreamfactory.com/u/Abhijit_Nair)\
**Post date:** [June 27, 2015, 11:02am UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/1 "2015-06-27T11:02:21Z")

</div>

I have tried everything to get the file, upload using custom script but in vain. How can I accomplish this, the way we do using angular form data?

This is my code

```
var file = event.record[0];
var options = {
    "CURLOPT_POSTFIELDS": '-----------------------------330603924205692451810523103\r\nContent-Disposition: form-data; name="files"; filename="test.txt\r\nContent-Type: text/plain\r\n'+file+'\r\n-----------------------------330603924205692451810523103--',
    "CURLOPT_HTTPHEADER": ["Content-type: multipart/form-data; boundary=---------------------------330603924205692451810523103"]
};
return platform.api.post("S3/bucket_name/container/folder/test.txt", null, options);
```

---

<div class="post-metadata">

**Author:** ![formerstaff](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/formerstaff/32/1133_2.png) [@formerstaff](https://community.dreamfactory.com/u/formerstaff)\
**Post date:** [June 29, 2015, 6:10pm UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/2 "2015-06-29T18:10:40Z")

</div>

Hey Abhijit, have you checked out the File Storage Services documentation? Specifically, the section on creating files has an example, written in Angular, for uploading files to your file storage service.

[https://github.com/dreamfactorysoftware/dsp-core/wiki/File-Storage-Services#creating-files](https://github.com/dreamfactorysoftware/dsp-core/wiki/File-Storage-Services#creating-files)

---

<div class="post-metadata">

**Author:** ![Abhijit\_Nair](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Abhijit\_Nair](https://community.dreamfactory.com/u/Abhijit_Nair)\
**Post date:** [June 30, 2015, 7:30am UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/3 "2015-06-30T07:30:54Z")

</div>

I can do it using angular and dreamfactory but I am trying to achieve the same using server side scripting for some reason. But it seems it doesn’t work that way. Is there a solution for server side scripting?

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [June 30, 2015, 6:43pm UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/4 "2015-06-30T18:43:51Z")

</div>

What is the format of your POST script? Generically, making API calls within scripting will take the form

```
platform.api.post( "service[/resource[/resource_id]]"[, payload] );

```

[API Access via Scripts](https://github.com/dreamfactorysoftware/dsp-core/wiki/API-Access-via-Scripts)

---

<div class="post-metadata">

**Author:** ![jkhong](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jkhong](https://community.dreamfactory.com/u/jkhong)\
**Post date:** [July 1, 2015, 9:24am UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/5 "2015-07-01T09:24:05Z")

</div>

I’ve been trying to do something similar, but it seems like custom scripts don’t have a event.request.files object. Is that true?

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [July 1, 2015, 6:28pm UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/6 "2015-07-01T18:28:13Z")

</div>

How is the file uploaded? Can you post an example of the REST call that POSTs the file, plus the part of your script that handles it and POSTs the payload to its destination?

---

<div class="post-metadata">

**Author:** ![Abhijit\_Nair](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Abhijit\_Nair](https://community.dreamfactory.com/u/Abhijit_Nair)\
**Post date:** [July 2, 2015, 12:25pm UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/7 "2015-07-02T12:25:11Z")

</div>

@jkhong, ya its true that event.request.files object doesn’t work in custom script. In fact i get nothing in event.request object on file upload.

@jeffreystables, below is the code

**CLIENT CODE**

```
var fd = new FormData();
fd.append('files', $scope.myFile);
$http.post("http://my_ip/rest/system/script/testFile?app_name=APP_NAME&is_user_script=true", fd, {
     transformRequest: angular.identity,
     headers: {'Content-Type': undefined}
});
```

---

<div class="post-metadata">

**Author:** ![jeffreystables](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/jeffreystables/32/173_2.png) [@jeffreystables](https://community.dreamfactory.com/u/jeffreystables)\
**Post date:** [July 27, 2015, 1:29pm UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/8 "2015-07-27T13:29:51Z")

</div>

How are you handling the uploaded file in your custom script? You can just post the part of your script that handles it and POSTs the payload to its destination.

---

<div class="post-metadata">

**Author:** ![regalartech](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@regalartech](https://community.dreamfactory.com/u/regalartech)\
**Post date:** [March 5, 2019, 6:14pm UTC](https://community.dreamfactory.com/t/how-to-upload-a-file-using-custom-script/1228/9 "2019-03-05T18:14:09Z")

</div>

hey Planning for the custom script for upload , any update ? is it possible or any other solution ?
