Uploading data
While using Prism API, there will be times that data will need to be uploaded. One can do this by generating a upload url, and sending a PUT request with the appropriate file.
Examples
Below are examples of the two step process to generate an upload URL and uploading a zip file of capture data. These are by no means extensive and performant examples, and are here only to serve as inspiration for possible implementation. Frameworks and languages will have alternative and preferred ways of implementing.
1. Generate the upload URL for scan capture data
curl --location --request POST 'https://sandbox-api.prismlabs.tech/scans/2b4487fc-ede7-41f6-8281-124b4a22ddd6/upload-url' \
--header 'Authorization: Bearer GENERATED_ACCESS_TOKEN' \
--header 'Accept: application/json;v=1'
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://sandbox-api.prismlabs.tech/scans/2b4487fc-ede7-41f6-8281-124b4a22ddd6/upload-url',
'headers': {
'Authorization': 'Bearer GENERATED_ACCESS_TOKEN',
'Accept': 'application/json;v=1'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import http.client
conn = http.client.HTTPSConnection("sandbox-api.prismlabs.tech")
payload = ''
headers = {
'Authorization': 'Bearer GENERATED_ACCESS_TOKEN',
'Accept': 'application/json;v=1'
}
conn.request("POST", "/scans/2b4487fc-ede7-41f6-8281-124b4a22ddd6/upload-url", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
2. Uploading the zipped capture data
curl --location --request PUT 'https://prism-api-data-sandbox-prod.s3.us-east-2.amazonaws.com/upload/24fe10c1-a082-4378-a542-5cd7efaf3870/acfd84be-0b54-480d-bacf-0bc58b5b13a7/capture-data/acfd84be-0b54-480d-bacf-0bc58b5b13a7.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZK5N6YRBOD3HCV4K%2F20221221%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20221221T064722Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEE8aCXVzLWVhc3QtMiJHMEUCIQCzgnix71EkjiEmkmX3RQ90D0421RhDvnj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m9DD7ltdiqm9sUCSfKgfgJ%2F2a9USHh25YVRcf9bxh4AnuYg13AcdjTpPdeS%2Fd3expaA2BXKSB7ttws1b9TizaBk7cnUknbEKK941vOlz0F7lwneaBRRUoDNVYtDlE%2BlFL%2Fbz%2FtrvejOscItx7%2BKEVw%2BKw5C6Yi&X-Amz-Signature=9f39e5d18cfbcbfc548af3c90e551c6fd8a7ad8a1f3d46211dc644f341ad78df&X-Amz-SignedHeaders=host&x-id=PutObject' \
--header 'Content-Type: application/zip' \
--form '=@"/path/to/good-scan-data.zip"'
var request = require('request');
var fs = require('fs');
var options = {
'method': 'PUT',
'url': 'https://prism-api-data-sandbox-prod.s3.us-east-2.amazonaws.com/upload/24fe10c1-a082-4378-a542-5cd7efaf3870/acfd84be-0b54-480d-bacf-0bc58b5b13a7/capture-data/acfd84be-0b54-480d-bacf-0bc58b5b13a7.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZK5N6YRBOD3HCV4K%2F20221221%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20221221T064722Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEE8aCXVzLWVhc3QtMiJHMEUCIQCzgnix71EkjiEmkmX3RQ90D0421RhDvnjxc%2FuURE58EAIgUPFrKmZipwuZHF5i6cNK17PU7PWOUgwf7ZVhja6w6ioqmQUIiP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARADGgw2NDE5MjU1NjM0NTgiDFczVjg%2BXyaWe0KYKSrtBADOoj1wExNQnVwNIIO44MislRIfbVsaBaaN3DMF66hmtEgO2XHoTZitXnWSjif94jiSwRTV6O8ieQAO4iBTWEGcDRB7hm7LyrzZzWHZt33uW4H1yfv4MIe1G%2BJQ02zfZZzSx3l7UAQ%2Bn%2Bea0trVEp0pUuQZOBkGBwavrZxl6fWemzd53ft9ZzQyt1Ut%2FgvPvbPQDtG9IXuuUIBGp0Qh2mhee7WaiDa%2BaB%2Fs2JgAvwpHiKIsKdsck1a6zBAr6cT6Yn6%2Bx8FHaGhl7UPQxH1rh475nLmsfcpGcokjtAVzbp970XZaJmHihELEoVCSz0BwZAhTZSopgX4Sm8u%2BljREiiC5Foj8s%2BQzf%2FLc2mY6Is7m8YbylXhjTwZxq8ULi8EJzmapXEpRw1%2BZJfkgX5MhsJAsx01UPXLv0ieXTIUrv5INGVZ2tDSHXCrCJtoXWOXl5HAaHyyq%2BAOUvNyYyiuuzAjGE2Zeb%2B9OXSFIUFuuBF5lxng3fIplwtq0hiXqyrBIQM9gZ30ss8zRFfFbr2St1y4z6zCM3ahn0TKFOHQZWF9J7uSeuI%2FuDuyIc9G2zVhScgdj%2BJD%2BX3Fs%2FgXcVkW%2FfsUSiQEXss0hcd286wYo3ur7l7DezXznSjnxOu0XUi7zuZUgWgU0rxapsInrOBw1Sz6sjrq5gzEA%2B4cML0KEkqtU9IliJeofmqXGeDVaghGajXpASwD6w%2FtNsFAVulOQiqVpbGQ0ibMLht5bjXrLmjrggx9ZkLYTgRnecnC4tqA9crnPah32qM37sxX9B5Eb%2F6jYpwaU5dq4tl5glcSqilesuDb%2BGbhiTvlwN7YR9zD614qdBjqbAe0AxtJOaCyE201mpBnNm7cZWoyw3jI8aDymbZG%2FyeIxxvJi7Fm9DD7ltdiqm9sUCSfKgfgJ%2F2a9USHh25YVRcf9bxh4AnuYg13AcdjTpPdeS%2Fd3expaA2BXKSB7ttws1b9TizaBk7cnUknbEKK941vOlz0F7lwneaBRRUoDNVYtDlE%2BlFL%2Fbz%2FtrvejOscItx7%2BKEVw%2BKw5C6Yi&X-Amz-Signature=9f39e5d18cfbcbfc548af3c90e551c6fd8a7ad8a1f3d46211dc644f341ad78df&X-Amz-SignedHeaders=host&x-id=PutObject',
'headers': {
'Content-Type': 'application/zip'
},
formData: {
'': {
'value': fs.createReadStream('/path/to/good-scan-data.zip'),
'options': {
'filename': 'good-scan-data.zip',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import http.client
import mimetypes
from codecs import encode
conn = http.client.HTTPSConnection("prism-api-data-sandbox-prod.s3.us-east-2.amazonaws.com")
dataList = []
boundary = 'wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T'
dataList.append(encode('--' + boundary))
dataList.append(encode('Content-Disposition: form-data; name=; filename={0}'.format('good-scan-data.zip')))
fileType = mimetypes.guess_type('/path/to/good-scan-data.zip')[0] or 'application/octet-stream'
dataList.append(encode('Content-Type: {}'.format(fileType)))
dataList.append(encode(''))
with open('/path/to/good-scan-data.zip', 'rb') as f:
dataList.append(f.read())
dataList.append(encode('--'+boundary+'--'))
dataList.append(encode(''))
body = b'\r\n'.join(dataList)
payload = body
headers = {
'Content-Type': 'application/zip',
'Content-type': 'multipart/form-data; boundary={}'.format(boundary)
}
conn.request("PUT", "/upload/24fe10c1-a082-4378-a542-5cd7efaf3870/acfd84be-0b54-480d-bacf-0bc58b5b13a7/capture-data/acfd84be-0b54-480d-bacf-0bc58b5b13a7.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZK5N6YRBOD3HCV4K%252F20221221%252Fus-east-2%252Fs3%252Faws4_request&X-Amz-Date=20221221T064722Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEE8aCXVzLWVhc3QtMiJHMEUCIQCzgnix71EkjiEmkmX3RQ90D0421RhDvnjxc%252FuURE58EAIgUPFrKmZipwuZHF5i6cNK17PU7PWOUgwf7ZVhja6w6ioqmQUIiP%252F%252F%252F%252F%252F%252F%252F%252F%252F%252FARADGgw2NDE5MjU1NjM0NTgiDFczVjg%252BXyaWe0KYKSrtBADOoj1wExNQnVwNIIO44MislRIfbVsaBaaN3DMF66hmtEgO2XHoTZitXnWSjif94jiSwRTV6O8ieQAO4iBTWEGcDRB7hm7LyrzZzWHZt33uW4H1yfv4MIe1G%252BJQ02zfZZzSx3l7UAQ%252Bn%252Bea0trVEp0pUuQZOBkGBwavrZxl6fWemzd53ft9ZzQyt1Ut%252FgvPvbPQDtG9IXuuUIBGp0Qh2mhee7WaiDa%252BaB%252Fs2JgAvwpHiKIsKdsck1a6zBAr6cT6Yn6%252Bx8FHaGhl7UPQxH1rh475nLmsfcpGcokjtAVzbp970XZaJmHihELEoVCSz0BwZAhTZSopgX4Sm8u%252BljREiiC5Foj8s%252BQzf%252FLc2mY6Is7m8YbylXhjTwZxq8ULi8EJzmapXEpRw1%252BZJfkgX5MhsJAsx01UPXLv0ieXTIUrv5INGVZ2tDSHXCrCJtoXWOXl5HAaHyyq%252BAOUvNyYyiuuzAjGE2Zeb%252B9OXSFIUFuuBF5lxng3fIplwtq0hiXqyrBIQM9gZ30ss8zRFfFbr2St1y4z6zCM3ahn0TKFOHQZWF9J7uSeuI%252FuDuyIc9G2zVhScgdj%252BJD%252BX3Fs%252FgXcVkW%252FfsUSiQEXss0hcd286wYo3ur7l7DezXznSjnxOu0XUi7zuZUgWgU0rxapsInrOBw1Sz6sjrq5gzEA%252B4cML0KEkqtU9IliJeofmqXGeDVaghGajXpASwD6w%252FtNsFAVulOQiqVpbGQ0ibMLht5bjXrLmjrggx9ZkLYTgRnecnC4tqA9crnPah32qM37sxX9B5Eb%252F6jYpwaU5dq4tl5glcSqilesuDb%252BGbhiTvlwN7YR9zD614qdBjqbAe0AxtJOaCyE201mpBnNm7cZWoyw3jI8aDymbZG%252FyeIxxvJi7Fm9DD7ltdiqm9sUCSfKgfgJ%252F2a9USHh25YVRcf9bxh4AnuYg13AcdjTpPdeS%252Fd3expaA2BXKSB7ttws1b9TizaBk7cnUknbEKK941vOlz0F7lwneaBRRUoDNVYtDlE%252BlFL%252Fbz%252FtrvejOscItx7%252BKEVw%252BKw5C6Yi&X-Amz-Signature=9f39e5d18cfbcbfc548af3c90e551c6fd8a7ad8a1f3d46211dc644f341ad78df&X-Amz-SignedHeaders=host&x-id=PutObject", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Last updated