upload
Upload one or more photos to the server.
API version
1.0
Description
An upload is done by posting one or more files to the upload URL as content-type multipart/form-data.
It is possible to upload multiple files with one request. It is also possible to attach metadata information as a JSON-Object that will be written to the file once it has been uploaded to the server.
Prerequisites
- Make sure that PicApport is not running in demo-mode (set server.demomode=false)
- Make sure the the user you are using for the WebApi context has the permission to upload photos.
(Test with PicApport if you are not sure) - Make sure that PicApports upload function is configured properly (upload.* parameter on PicApport-Server Guide)
How it works
Check the uploadPhotos() function in sourcecode(select view source) of PicApport WebApi-frontend on https://en.onlinedemo.picapport.de/picapport-webapitest.html.
var formData = new FormData(); var photos = document.querySelector( "input[type='file'][multiple]" ); formData.append( 'metadata' , JSON.stringify({ "title" : "Optional title" , "description" : "Optional description" , "rating" : 5, "tags" : [ "tag1" , "tag2" ], "persons" : [ "person 1" , "person 2" ], })); for ( var i = 0; i < photos.files.length; i++) { formData.append( 'photos' , photos.files[i]); } fetch(createUrl( "upload" , [ "apisid" ]), { method: 'POST' , body: formData }) .then(response => response.json()) .then(json => console.log( "Upload result: " , json)) . catch (error => console.log( "UploadError: " + error)); |
Metadata is applied to all photos until they are changed. So the following is possible:
var formData = new FormData(); formData.append( 'metadata' , JSON.stringify(metadata1 formData.append( 'photos' , photoFile1.... formData.append( 'metadata' , JSON.stringify(metadata2 formData.append( 'photos' , photoFile2.... formData.append( 'photos' , photoFile3.... POST formdata using fetch..... |
In the example above photoFile1 gets metadata1 and photoFile2+photoFile3 get metadata2
Version Note: Since version 8.3 it is also possible to have e unique photoID field in the metadata-JSON of the request.
Version Note: Since version 9.1.04 it is also possible to have e unique doSyncCheck field in the metadata-JSON of the request.
- doSyncCheck optional Parameter. (default = true)
If set to false, the check if the photo has already been transferred is omitted.
Important: Regardless of the setting of this parameter the photo will still not be accepted if a photo with this ID exists in the database.
Parameter
apisid | string | 7.4 | yes | Based on the setting of webapi.default.uid in picapport.properties you may provide one of the following values
|
Result
mime type | application/json |
---|---|
content | Information about the upload result |
http status codes |
|
Result:JSON
apisid | string | 7.4 | Session-ID returned from createWebApiSession |
processedFiles | array | 7.4 | Each array element has the following members |
fileName | string | 7.4 | The filename used on the PicApport Server |
contentType | string | 7.4 | image/jpeg for .jpg Files |
sizeInBytes | int | 7.4 | The size of the file in bytes |
photoID | string | 7.4 | The unique PicApport photoID created after the upload. This ID may be used to access the photo. |
result | string | 7.4 |
|