Upload a photo file to associate with a record using multipart/form-data with photo[access_key] and photo[file]. Let your HTTP client set the multipart Content-Type header and boundary. Supported formats are JPEG, PNG, GIF, TIFF, WebP, HEIC, and HEIF. The server detects the type from the actual file bytes rather than the filename, extension, or declared MIME type, and stores the detected content type. Unsupported content is rejected with a file validation error. A verified image with a valid new access key can create a photo. Uploading to an existing photo's access key requires update permission for that photo; an access key alone is not authorization. Both successful creation and authorized updates return 201 with photo metadata. Image processing occurs asynchronously.
| Time | Status | User Agent | |
|---|---|---|---|
Retrieving recent requests… | |||
Uploading or updating a photo
Send a multipart/form-data request with photo[access_key], a UUID identifying the photo. A valid new access key creates a photo and requires photo[file]. Updating an existing photo requires update permission for that photo; knowing its access key alone does not grant permission.
For an authorized update, include photo[file] to replace the image, or omit it to retain the existing file. An existing photo without a file, such as a placeholder, still requires a file.
jQuery Web Form Example
<form>
<input type="file" name="photo" id="photo" /><br /><br />
<input type="button" id="upload" value="upload" />
</form>$(document).ready(function(){
/**
* Generates a GUID string.
* @returns {String} The generated GUID.
* @example af8a8416-6e18-a307-bd9c-f2c947bbb3aa
* @author Slavik Meltser ([email protected]).
* @link http://slavik.meltser.info/?p=142
**/
function guid() {
function _p8(s) {
var p = (Math.random().toString(16)+"000000000").substr(2,8);
return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;
}
return _p8() + _p8(true) + _p8(true) + _p8();
}
$("#upload").click(function(){
var formData = new FormData();
formData.append("photo[access_key]", guid());
formData.append("photo[file]", $("#photo")[0].files[0]);
$.ajax({
type: "POST",
url: "https://api.fulcrumapp.com/api/v2/photos.json",
data: formData,
cache: false,
contentType: false,
processData: false,
dataType: "json",
headers: {
"X-ApiToken": "my-api-key"
},
success: function (data) {
// do something!
console.log(data);
}
});
});
});