Created
July 7, 2016 17:42
-
-
Save ivanoats/3ef8a1c85e698b20318c5f09d2bcf368 to your computer and use it in GitHub Desktop.
createImage on Contentful.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function createImage (image, space) { | |
try { | |
const result = await space.createAsset({ | |
sys: { | |
createdAt: image.created_at, | |
updatedAt: image.updated_at, | |
}, | |
fields: { | |
title: { 'en-US': image.title }, | |
file: { | |
'en-US': { | |
contentType: image.page_image_content_type, | |
fileName: image.page_image_file_name, | |
upload: `${assetHost}/custom_page_images/${image.id}/page_images/${image.page_image_file_name}`, | |
}, | |
}, | |
}, | |
}) | |
return await space.processAssetFile(result, 'en-US') | |
} catch (error) { | |
return console.error(`API ERROR (image) ${error}`) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment