File Upload API Follow
POST|PUT {host}:{port}/ServiceManager/Macro/FileManager
Uploading a file to the ServiceManager server is done by invoking HTTP request to the URL above, providing the file as multipart/form-data or base64 encoded.
multipart/form-data Upload
HTTP POST or PUT.
Via JavaScript:
var formData = new FormData();
formData.append('path', 'www/upload');
formData.append('file', $('input[type="file"]').files[0]);
formData.append('absolute', false);
$.ajax({
url: getServiceManagerHost() + '/ServiceManager/Macro/FileManager',
data: formData,
type: 'POST',
contentType: false, // (requires jQuery 1.6+)
processData: false,
success: function(response) {
store('pathOnServer', response.data);
}, error: function(jqXHR, textStatus, errorMessage) {
showInfoPopup('upload failed', errorMessage);
}
});
OR via input type="file and form submit:
<form enctype="multipart/form-data" method="post"
action="http://localhost:8080/ServiceManager/Macro/FileManager">
<input type="file" name="uploadedFile">
<input type="submit" value="Upload">
</form>
Base64 Upload
HTTP PUT, with body as followed:
{
"filename" :"cat.jpg",
"path": "uploads",
"content": "data:image/gif;base64,R0lGODlhPQBE..."
}
- filename: name for the file as it would be saved on the server.
- path: (optional) path on the server to save the file to.
If no path is set, the file will be uploaded to <LocalFolder>/temp/<timestamp>.<extension> . - content: the base64 representation of the file.
Upload via JavaScript service
From a JavaScript service, you may use the Files.upload() command to upload a base64-encoded file.
It returns the path of the uploaded file:
Documentation is available in the CodeAssist of the JavaScript editor.
Response
On successful upload, you'll receive "success: true" and the path of the uploaded file:
{
success: true,
objectName: "java.lang.String",
data: "C:/Users/Alex/ServiceManager/temp/74673145_10221374187127825_3752357143756406784_n.jpg"
}
Comments
0 comments
Please sign in to leave a comment.