Create a File

post
Create a File

https://api.moltin.com/v2/files
Request
Response
Headers
Authorization
required
string
The Bearer token to grant access to the API
Form Data Parameters
file
required
string
The file you want to upload
public
required
boolean
true, false
201: Created
{
"data": {
"type": "file",
"id": "f8cf26b3-6d38-4275-937a-624a83994702",
"link": {
"href":
"https://s3-eu-west-1.amazonaws.com/bkt-svc-files-cmty-api-moltin-com/e8c53cb0-120d-4ea5-8941-ce74dec06038/f8cf26b3-6d38-4275-937a-624a83994702.png"
},
"file_name": "f6669358-85db-4367-9cde-1deb77acb5f4.png",
"mime_type": "image/png",
"file_size": 110041,
"public": true,
"meta": {
"dimensions": {
"width": 1000,
"height": 1000
},
"timestamps": {
"created_at": "2018-03-13T13:45:21.673Z"
}
},
"links": {
"self":
"https://api.moltin.com/v2/files/f8cf26b3-6d38-4275-937a-624a83994702"
}
}
}
cURL
Moltin Request
curl -X POST https://api.moltin.com/v2/files \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer XXXX" \
-F file=@path/to/file \
-F public=true
const { createClient } = require('@moltin/request')
const FormData = require("form-data")
const moltin = new createClient({
client_id: 'X',
client_secret: 'X'
})
const formData = new FormData()
formData.append("file_name", fileName)
formData.append("public", "true")
formData.append("file", buffer, { filename: fileName })
const headers = {
"Content-Type": formData.getHeaders()["content-type"]
}
const data = {
body: formData
}
moltin
.post("files", data, headers)
.then(console.log(data))
.error(console.error(error))