Ссылка на файл загрузки окна
Этот код ниже успешно загружается, но содержимое повреждено и нечитабельно.
Код: Выделить всё
// Create a new RESTMessageV2 object
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('https://upload.box.com/api/2.0/files/content');
r.setHttpMethod('POST');
// Set the authorization header
r.setRequestHeader('Authorization', 'Bearer ');
// Define the boundary string
var boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
// Set the Content-Type header with the boundary
r.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
// Define the attributes part of the multipart body
var attributes =
'--' + boundary + '\r\n' +
'Content-Disposition: form-data; name="attributes"\r\n\r\n' +
'{"name": "schedule1.txt", "parent": {"id": "0"}}\r\n';
// Define the file part of the multipart body
var file =
'--' + boundary + '\r\n' +
'Content-Disposition: form-data; name="file"; filename="schedule1.txt"\r\n' +
'Content-Type: text/plain\r\n\r\n' +
'BASE64_ENCODED_FILE_CONTENT' + '\r\n' +
'--' + boundary + '--\r\n'; // Closing boundary
var requestBody;
// Set the full request body (attributes and file parts)
requestBody = attributes + file;
var gr = new GlideRecord('sys_attachment');
if (gr.get('sys_id', '91b8bb9153c11210137779a0a0490e4e')) {
var attachment = new GlideSysAttachment();
var fileContent = attachment.getBytes(gr);
var base64EncodedFile = GlideStringUtil.base64Encode(fileContent);
gs.info(base64EncodedFile);
// Replace 'BASE64_ENCODED_FILE_CONTENT' in the request body with the actual encoded content
requestBody = requestBody.replace('BASE64_ENCODED_FILE_CONTENT', base64EncodedFile);
}
r.setRequestBody(requestBody);
// Execute the REST call
var response = r.execute();
var responseBody = response.getBody();
gs.info('Response: ' + responseBody);
Я также использовал новый java.io.ByteArrayInputStream(), но тоже не сработал.
Как я могу отправить файл который извлекается из таблицы servicenow в коробку?
Я пробовал использовать writeString, также используя Packages.java.lang.String
Все загруженное содержимое поврежден, невозможно открыть его в консоли окна.
Нечитаемый файл перед загрузкой
Нечитаемый файл после загрузки
Подробнее здесь: https://stackoverflow.com/questions/791 ... servicenow
Мобильная версия