PXM Products/
PXM Product Assets/
Create a File

Create a File

POST Create a File

https://api.moltin.com/v2/files

The following table describes the file types that can be uploaded to Elastic Path Commerce Cloud.

File ExtensionDescription
.gifGraphics Interchange Format (GIF)
.jpg/jpegJoint Photographic Experts Group (JPEG) format
.pngPortable graphics format
.webpWeb picture format
.mp4Moving Picture Experts Group (MPEG) format
.movQuickTime Movie format
.pdfPortable Document Format
.svgScalable Vector Graphics format
.usdzUniversal Scene Description Format
.glbGlobal File format
.jp2Compressed bitmap image saved in Joint Photographic Experts Group (JPEG) format
.jxrExtended range for Joint Photographic Experts Group (JPEG) format
.aacAdvanced Audio Coding (AAC) format
.vrmlVirtual Reality Modelling Language (VRML) format
.doc(x)Microsoft Word Open XML format
.ppt(x)Microsoft PowerPoint Open XML format
.xls(x)Microsoft Excel Open XML format

If you use file types that are not supported, a 400: Forbidden response with This file type is not supported message is returned.

Parameters

Form data parameters - upload image

Specify the following parameters to upload a file:

NameRequiredTypeDescription
fileRequiredstringIndicates the file you want to upload.
DEPRECATED publicRequiredbooleanIndicates whether the file is public.

Form data parameters - image URL

Specify the following parameter to reference a file stored at a specific location:

NameRequiredTypeDescription
file_locationstringRequiredThe URL that points to an image file.

If you include file or public with file_location, the service returns a 400 error.

Headers

NameRequiredTypeDescription
AuthorizationRequiredstringThe Bearer token required to get access to the API.

Request Examples

Curl - upload image

curl -X POST https://api.moltin.com/v2/files \
    -H "Content-Type: multipart/form-data" \
    -H "Authorization: Bearer XXXX" \
    -F file=@path/to/file \

Curl - image URL

curl -X POST https://api.moltin.com/v2/files \
    -H "Content-Type: multipart/form-data" \
    -H "Authorization: Bearer XXXX" \
    -F file_location=https://my.example.com/images/abc.png \

JavaScript SDK

// File upload with form-data
const FormData = require("form-data");
const formData = new FormData();
formData.append("file", buffer);


// Optional: may be required in Node.js environments
const contentType = formData.getHeaders()["content-type"];


// Where `EPCC` is an authenticated client
await EPCC.Files.Create(formData, contentType);


// File upload by image URL
await EPCC.Files.Link("https://my.example.com/images/abc.png");

Response Example

201 Created

{
    "data": {
        "type": "file",
        "id": "f8cf26b3-6d38-4275-937a-624a83994702",
        "link": {
            "href": "https://files-eu.epusercontent.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,
        "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"
        }
    }
}

Was this helpful?

Previous
Get a File

Learn

Docs