HTTP:
POST /api/file HTTP/1.1
Host: 192.168.24.83:8080
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache
Postman-Token: 63c5cd27-47df-20eb-380a-144c39017b9b
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="hello.txt"
Content-Type: application/txt
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="auth"
Content-Type: application/json
"{'user':'admin', 'password':'password', 'path':'/mapoteca'}"
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Python:
import os
import json
import requests
url = 'http://localhost:8080/api/file'
auth = {'user':'<ALFRESCO_USER>', 'password':'<ALFRESCO_PASSWORD>', 'path':'/User Homes/<ALFRESCO_USER>'}
form = {
'auth': (None, json.dumps(auth), 'application/json'),
'file': ('hello.txt', open('hello.txt', 'rb'), 'text/plain')
}
requests.post(url=url, files=form).content
JavaScript:
const url = 'http://localhost:8080/api/file'
const auth = {'user':'<ALFRESCO_USER>', 'password':'<ALFRESCO_PASSWORD>', 'path':'/User Homes/<ALFRESCO_USER>'}
let form = new FormData()
form.append('auth', new Blob([JSON.stringify(auth)], {type: 'application/json'}))
form.append('file', new Blob(['Hello World'], {type: 'application/txt'}), 'hello.txt') // or
// form.append('file', document.forms[formName].file.files[0]) // from input type == 'file'
// let request = { url: url, method: 'POST', data: form }
let xhr = new XMLHttpRequest()
xhr.open( 'POST', url, true)
// xhr.setRequestHeader('Content-Type', 'multipart/form-data') // optional
xhr.onreadystatechange = function () {console.log(this.responseText)}
xhr.send(form)
Response example:
{"name":"hello.txt","length":11,"id":"837b14bb-4c24-4562-bf49-a243d621bf32","mimeType":"application/txt","version":"3.0"}
Python:
import os
import json
# download latest version or specific version
url = 'http://localhost:8080/api/file/f0f066fb-1b1e-4145-a02d-7968f5a3d507'
# url = 'http://localhost:8080/api/file/f0f066fb-1b1e-4145-a02d-7968f5a3d507?version=2.0'
auth = {'user':'<ALFRESCO_USER>', 'password':'<ALFRESCO_PASSWORD>', 'path':'/User Homes/<ALFRESCO_USER>'}
data = {
'auth': auth,
}
requests.post(url=url, json=data).content
JavaScript:
// download latest version or a specific version
const url = 'http://localhost:8080/api/file/f0c3ebd7-869a-49c8-bfaa-c2868ccad7ae'
// const url = 'http://localhost:8080/api/file/f0f066fb-1b1e-4145-a02d-7968f5a3d507?version=2.0'
const auth = {'user':'<ALFRESCO_USER>', 'password':'<ALFRESCO_PASSWORD>', 'path':'/User Homes/<ALFRESCO_USER>'}
let data = {
'auth': auth
}
setDownloadClickEvent = function(el, filename, contentType, content) {
const uri = `data:${contentType};base64,${content}`
downloadLink = el
downloadLink.href = uri
downloadLink.target = '_blank'
downloadLink.download = filename
return downloadLink;
}
let xhr = new XMLHttpRequest()
xhr.open( 'POST', url)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.onreadystatechange = function () {
// xhr.getAllResponseHeaders()
// window.open("data:" + xhr.getResponseHeader('Content-Type') + ";base64," + this.response, '_blank')
let link = setDownloadClickEvent(document.createElement('a'), 'test.pdf', xhr.getResponseHeader('Content-Type'), this.response)
link.click()
}
xhr.send(JSON.stringify(data))
Python:
import os
import json
# remove only latest version or all versions
url = 'http://localhost:8080/api/file/f0f066fb-1b1e-4145-a02d-7968f5a3d507'
# url = 'http://localhost:8080/api/file/f0f066fb-1b1e-4145-a02d-7968f5a3d507?allVersions=true'
auth = {'user':'<ALFRESCO_USER>', 'password':'<ALFRESCO_PASSWORD>', 'path':'/User Homes/<ALFRESCO_USER>'}
data = {
'auth': auth,
}
requests.delete(url=url, json=data).content
JavaScript:
// remove only latest version or all versions
const url = 'http://localhost:8080/api/file/f0c3ebd7-869a-49c8-bfaa-c2868ccad7ae'
// url = 'http://localhost:8080/api/file/f0f066fb-1b1e-4145-a02d-7968f5a3d507?allVersions=true'
const auth = {'user':'<ALFRESCO_USER>', 'password':'<ALFRESCO_PASSWORD>', 'path':'/User Homes/<ALFRESCO_USER>'}
let data = {
'auth': auth
}
let xhr = new XMLHttpRequest()
xhr.open( 'DELETE', url)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.onreadystatechange = function () {console.log(this.responseText)}
xhr.send(JSON.stringify(data))