• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

'HTTP/1.1 403 Forbidden', Unable to upload the document Adobe API serivces

New Here ,
Nov 11, 2024 Nov 11, 2024

Copy link to clipboard

Copied

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
 
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');
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
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
 
 
% 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
TOPICS
PDF Services API

Views

176

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

still looking for help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 13, 2024 Nov 13, 2024

Copy link to clipboard

Copied

It's hard to grok what you are doing here as I've never used matlab. To be clear, are you able to make the asset, but can't upload it? If so, that's not really an Adobe API issue, but just uploading content in matlab itself.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 14, 2024 Nov 14, 2024

Copy link to clipboard

Copied

I am really happy to see your kind reply.

 

Yes, you are right. I am not able to upload it, getting the error "HTTP/1.1 403 Forbidden"

 

Yes, it is proably matlab issue. I have been stuck here.

 

Any help in this regard or any wayout in this regard, would be highly appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 14, 2024 Nov 14, 2024

Copy link to clipboard

Copied

The best I can do is shared the Node.js code I use for this step:

 

async function uploadFile(url, filePath, mediaType) {

	let stream = fs.createReadStream(filePath);
	let stats = fs.statSync(filePath);
	let fileSizeInBytes = stats.size;

	let upload = await fetch(url, {
		method:'PUT', 
		redirect:'follow',
		headers: {
			'Content-Type':mediaType, 
			'Content-Length':fileSizeInBytes
		},
		duplex:'half',
		body:stream
	});

	if(upload.status === 200) return;
	else {
		throw('Bad result, handle later.');
	}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

I have the python script from the SDK, which is working pretty fine. The problem is with the matlab script, As I posted in thread

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

can you share the correct matlab code. or help me to correct the code, which I posted on the top?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 16, 2024 Nov 16, 2024

Copy link to clipboard

Copied

I can't, as I don't use Matlab. I'm sorry. Maybe try their support forums?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 19, 2024 Nov 19, 2024

Copy link to clipboard

Copied

LATEST

ok, anyway thanks for your time

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources