Question
'HTTP/1.1 403 Forbidden', Unable to upload the document Adobe API serivces
This is my matlab code. I am not able to upload the document getting the following error.
StatusLine: 'HTTP/1.1 403 Forbidden'
StatusCode: Forbidden
Header: [1×11 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
However, using python or postman I can upload the document. There is something wrong with the Matlab script.
%% Steps to upload a pdf to Adobe PDF Services API are provided by Adobe
%% Setup
% Get free client_id and client_secret in "Step 1 : Getting the access
% token" here: https://developer.adobe.com/document-services/docs/overview/pdf-services-api/gettingstarted
client_id = 'e2e64915d0b14bac99d3411138b0c586'; % Get a free client_id from link above
client_secret = 'p8e-YdyV3DudnX4tn3F7Z14FfwHnAQYAP0Ci';% Get a free client_secret from link above
filepath = './ocrInput.pdf'; % Any pdf file that you want to upload
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
%% Step 1: Get a token by submitting client_id and client_secret
header1 = HeaderField('Content-Type', 'application/x-www-form-urlencoded');
url1 = URI('https://pdf-services.adobe.io/token');
body1 = FormProvider(...
'client_id', client_id,...
'client_secret', client_secret...
);
response1 = RequestMessage('post', header1, body1).send(url1.EncodedURI);
token = response1.Body.Data.access_token;
response1.Body.Data.access_token = 'eyJhbGciOiJSUzI1NiIsIng1dSI6Imltc19uYTEta2V5LWF0LTEuY2VyIiwia2lkIjoiaW1zX25hMS1rZXktYXQtMSIsIml0dCI6ImF0In0.eyJpZCI6IjE3MzEwODE5MTkzODhfZDJhN2E1MjItZmZjNC00YTJkLTg1ODUtZWRiYzAzN2JiMDk2X3VlMSIsIm9yZyI6IkI3RjExREM0NjcyQTBEMzYwQTQ5NUU5QkBBZG9iZU9yZyIsInR5cGUiOiJhY2Nlc3NfdG9rZW4iLCJjbGllbnRfaWQiOiJlMmU2NDkxNWQwYjE0YmFjOTlkMzQxMTEzOGIwYzU4NiIsInVzZXJfaWQiOiIwRTk2MUREMTY3MkNEMjg2MEE0OTVGQ0ZAdGVjaGFjY3QuYWRvYmUuY29tIiwiYXMiOiJpbXMtbmExIiwiYWFfaWQiOiIwRTk2MUREMTY3MkNEMjg2MEE0OTVGQ0ZAdGVjaGFjY3QuYWRvYmUuY29tIiwiY3RwIjozLCJtb2kiOiI3NTYzNDdkYSIsImV4cGlyZXNfaW4iOiI4NjQwMDAwMCIsInNjb3BlIjoiRENBUEksb3BlbmlkLEFkb2JlSUQiLCJjcmVhdGVkX2F0IjoiMTczMTA4MTkxOTM4OCJ9.DdYNP6vZ27BiUja3na7_AiJece5UHRBhOioT8WOVIE-A7tOYlZJrs2AgDNCu259Q71tRJpJbYZ1hO2VNNGyZlJHrq-33kLXQRXg9B5LSnWe0JVHXxX1kWHr8Z5Qw6iV54Ehdta_gB1EvnVA8JO3Cmu3X7oXCOCn8aSseanUa3Xa6AgvWdh1Sv-w-GDbsvp17iPL4PirPqnVqOsOwx2V0NAgCsBJHcBWeqYT1Ci5RY_X3BZ3D_q6hzrZRq-EhYVhQPw804XtynjIuv-U4SEMTL_AM173B2fGnGs1ux_p94C_yB3BrNvKM5BKu6ztCrsUnd4DsapzWtG7E9UvVS13uNw'
disp(strcat("Token obtained: ", string(token)));
%% Step 2: Get an UploadURL by submitting the token from Step 1
url2 = 'https://pdf-services.adobe.io/assets';
body2 = struct(...
'mediaType', 'application/pdf'...
);
options2 = weboptions(...
'MediaType', 'application/json',...
'HeaderFields', {
'X-API-Key' client_id;...
'Authorization' token...
}...
);
response2 = webwrite(url2, body2, options2);
upload_url = response2.uploadUri;
disp(strcat("Upload URL obtained: ", string(upload_url)));
%upload_assetid = response2.assetID;
%% Step 3: Upload a pdf in binary form to Adobe PDF Services
% THIS IS THE PART THAT NEEDS CONSTRUCTION
% See Step 2, Part 2 in the link https://developer.adobe.com/document-services/docs/overview/pdf-services-api/gettingstarted
% Get required file size
fileInfo = dir(filepath);
fileSize = fileInfo.bytes;
% Get required Host
upload_url_components = URI(upload_url);
upload_url_components.Port = 62193;
% 62193
% 443
% dcplatformstorageservice-prod-us-east-1.s3-accelerate.amazonaws.com
header3 = HeaderField('Content-Type', 'application/pdf',...
'Host',upload_url_components.Host,...
'Content-Length',num2str(fileSize)...
);
disp(table([header3.Name]',[header3.Value]','VariableNames',{'Header','Value'}));
% Construct the request message - LIKELY SOURCE OF ERROR
body3 = FileProvider(filepath);
body3.FileSize = fileSize
request3 = RequestMessage('put',header3, body3);
completedrequest3 = complete(request3,upload_url);
% Send the request
[response3,sentrequest3,history3] = send(completedrequest3,upload_url);
disp(response3);
% response1 = RequestMessage('post', header1, body1).send(url1.EncodedURI);
% Construct the request message -
% Send the request
