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
{ | |
"id":xxx, | |
"customerKey":"xxx", | |
"objectID":"xxx", | |
"assetType":{ | |
"id":23, | |
"name":"jpg", | |
"displayName":"Image" | |
}, | |
"fileProperties":{ |
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
POST /asset/v1/content/assets | |
{ | |
"name": "Astro", | |
"assetType": { | |
"name": "png", | |
"id": 28 | |
}, | |
"file": "/9j/4AAQSkZJRgABAQAASABIAAD/2wBDAAQEBAQEBAcEBAcKBwcHCg0KCgoKDRANDQ0NDRAUEBAQEBAQFBQUFBQUFBQYGBgYGBgcHBwcHB8sDE94b5W7oHvIsTYPyGodpqA/ii4AwBAf+F//2Q==" | |
} |
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
var headerNames = ["Authorization"]; | |
var headerValues = ["Bearer " + accessToken]; | |
var jsonBody = { | |
"name": fileName, | |
"assetType": { | |
"name": assetName, | |
"id": assetTypeID | |
}, | |
"file": base64enc | |
}; |
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
//prepare data for API call | |
var base64enc = obj.base64enc; | |
var fileName = obj.fileName; | |
var assetName = obj.assetName; | |
//match asset type with uploaded file (https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/base-asset-types.htm) | |
var assetTypes = { ai: 16, psd: 17, pdd: 18, eps: 19, gif: 20, jpe: 21, jpeg: 22, jpg: 23, jp2: 24, jpx: 25, pict: 26, pct: 27, png: 28, tif: 29, tiff: 30, tga: 31, bmp: 32, wmf: 33, vsd: 34, pnm: 35, pgm: 36, pbm: 37, ppm: 38, svg: 39, "3fr": 40, ari: 41, arw: 42, bay: 43, cap: 44, crw: 45, cr2: 46, dcr: 47, dcs: 48, dng: 49, drf: 50, eip: 51, erf: 52, fff: 53, iiq: 54, k25: 55, kdc: 56, mef: 57, mos: 58, mrw: 59, nef: 60, nrw: 61, orf: 62, pef: 63, ptx: 64, pxn: 65, raf: 66, raw: 67, rw2: 68, rwl: 69, rwz: 70, srf: 71, sr2: 72, srw: 73, x3f: 74, "3gp": 75, "3gpp": 76, "3g2": 77, "3gp2": 78, asf: 79, avi: 80, m2ts: 81, mts: 82, dif: 83, dv: 84, mkv: 85, mpg: 86, f4v: 87, flv: 88, mjpg: 89, mjpeg: 90, mxf: 91, mpeg: 92, mp4: 93, m4v: 94, mp4v: 95, mov: |
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
//retrieve posted data | |
var jsonData = Platform.Request.GetPostData(); | |
var obj = Platform.Function.ParseJSON(jsonData); |
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
fetch("https://pub.s10.exacttarget.com/xxxxxxx", { //provide URL of the processing page | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json" | |
}, | |
body: JSON.stringify({ | |
base64enc: base64enc, | |
fileName: fileName, | |
assetName: assetName | |
}) |
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
var fileEncoded = reader.result; | |
var base64enc = fileEncoded.split(";base64,")[1]; | |
var fullFileName = document.getElementById("file").files[0].name; | |
var fileName = fullFileName.split(".")[0]; | |
var assetName = fullFileName.split(".")[1]; |
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
Please select a file to upload: | |
<br> | |
<input id="file" type="file" accept="image/*"> | |
<br> | |
<button id="button">Upload</button> |
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
document.getElementById('button').addEventListener('click', function() { | |
var files = document.getElementById('file').files; | |
if (files.length > 0) { | |
getBase64(files[0]); | |
} | |
}); | |
function getBase64(file) { | |
var reader = new FileReader(); | |
reader.readAsDataURL(file); |
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
Please select a file to upload: | |
<br> | |
<input id="file" type="file" accept="image/*"> | |
<br> | |
<button id="button">Upload</button> | |
<script runat="client"> | |
document.getElementById("button") | |
.addEventListener("click", function() { | |
var files = document.getElementById("file").files; |