Internal error 500 on upload file from REST API

cancel
Showing results for 
Search instead for 
Did you mean: 
alexandreb
Active Member II

Internal error 500 on upload file from REST API

Jump to solution

Hi,

I already had some trouble uploading a file from a node application to Alfresco, but this time I'm trying on a different way, and encountering different issue.

var http = require("http");

var options = {
      'host': 'localhost',
      'port': '8080',
      'path': '/alfresco/service/api/upload?alf_ticket='+ticket,
      'method': 'POST',
      'headers': {
        'Content-Type': 'application/json'
        }
    };

var body = {
       "name":"Name",
       "nodeType":"cm:content"
}

var req = http.request(options, function(res) {
          console.log('STATUS: ' + res.statusCode);
          console.log('HEADERS: ' + JSON.stringify(res.headers));
          res.setEncoding('utf8');
          res.on('data', function (chunk) {
            console.log('BODY: ' + chunk);
          });
        });

req.on('error', function(e) {
          console.log('problem with request: ' + e.message);
        });

        // write data to request body
        req.write(JSON.stringify(body));
        req.end();

The previous code is supposed to create a file in root ... sadly it return an error 500 internal error, here are the logs from the console :

STATUS: 500
HEADERS: {"server":"Apache-Coyote/1.1","cache-control":"no-cache","expires":"Thu, 01 Jan 1970 00:00:00 GMT","pragma":"no-cache","content-type":"application/json;charset=UTF-8","transfer-encoding":"chunked","date":"Thu, 01 Jun 2017 15:50:34 GMT","connection":"close"}
BODY: {
    "status" :
  {
    "code" : 500,
    "name" : "Internal Error",
    "description" : "An error inside the HTTP server which prevented it from fulfilling the request."
  },  

And here are the logs from Alfresco :

2017-06-01 17:50:34,025 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-1] Exception from executeScript: 05010348 Unexpected error occurred during upload of new content.
org.springframework.extensions.webscripts.WebScriptException: 05010348 Unexpected error occurred during upload of new content.
    at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1124)
    at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
    at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:519)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:587)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:656)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210)
    at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.alfresco.module.aosmodule.service.ContextRootFilter.doFilter(ContextRootFilter.java:93)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2403)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.mozilla.javascript.JavaScriptException: ReferenceError: Unexpected error occurred during upload of new content. (classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js#476)
    at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_12._c_main_4(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js:476)
    at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_12.call(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
    at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:74)
    at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_12._c_script_0(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js:480)
    at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_12.call(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
    at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_12.call(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
    at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_12.exec(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:509)
    at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:207)
    at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:219)
    at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:181)
    at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:109)
    at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1376)
    at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
    ... 36 more

If anyone have any idea, thank you in advance.

1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: Internal error 500 on upload file from REST API

Jump to solution

Looks like you are manually placing the file path as string. It will not work. File has to be attached. This is how we select a file in Postman. Rest of the params could be as is.

select filedata.png

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

15 Replies
kaynezhang
Advanced

Re: Internal error 500 on upload file from REST API

Jump to solution

From your code I haven't seen any destination path or noderef parameter.

ni0ni0s
Member II

Re: Internal error 500 on upload file from REST API

Jump to solution

i have this code but i can't upload file into enywhere.
can you give an example of jsonData array syntax?
i have the default installation of alfresco and i have achieved to create direcory.
i cant find the way to upload file.
thanks

<?php

//API Url
$url = '192.168.1.1:8080/alfresco/s/api/upload?alf_ticket=TICKET_e0113b837d77e99b3e0a33da110e12be52bded4e';

//Initiate cURL.
$ch = curl_init($url);

//The JSON data.
$jsonData = array(
"filedata"=> "test.txt",
"siteid"=> "siteName",
"containerid"=> "documentLibrary",
"description"=> "A shiny new node"
);

//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

//Execute the request
$result = curl_exec($ch);

?>

abhinavmishra14
Advanced

Re: Internal error 500 on upload file from REST API

Jump to solution

seems like you are trying to upload content less object. I dont see the correct filedata option. 

Please look at this documentation, you must pass all required params in order to get succesful response. 

Here is the detailed description for upload api:

Upload file content and meta-data into repository.

POST /alfresco/service/api/upload

 

HTML form data
  • filedata, (mandatory) HTML type file
  • You must specify one of:
    • destination (the folder NodeRef where the node will be created)
    • updateNodeRef (the NodeRef of an existing node that will be updated)
    • siteid and containerid (the Site name and the container in that site where the document will be created)
  • uploaddirectory - name of the folder (either in the site container or the destination) where the document will be uploaded. This folder must already exist
  • description - Description for a version update (versionDescription)
  • contenttype - The content type that this document should be specialised to
  • majorversion
  • overwrite
  • thumbnails
Return content
  • nodeRef

Return status: STATUS_OK (200)

The web script description document specifies the following options:
Value Description
json The default response format
user The authentication access
required The transaction level
any The format style
 
 
~Abhinav
(ACSCE, AWS SAA, Azure Admin)
ni0ni0s
Member II

Re: Internal error 500 on upload file from REST API

Jump to solution

there is no good description for everything. can you give an example?

 

$jsonData = array(
"filedata"=> "@test.txt",
"siteid"=> "defend",
"containerid"=> "documentLibrary",
"uploaddirectory"=> "./",
"description"=> "test",
"contenttype"=> "text/plain",
"majorversion"=> "1",
"overwrite"=> "1",
"thumbnails"=> ""
);

abhinavmishra14
Advanced

Re: Internal error 500 on upload file from REST API

Jump to solution

I have used it with Java language. You can find the code and example here: http://javaworld-abhinav.blogspot.com/2014/09/upload-documents-to-alfresco-using-rest.html 

Parameters are highlighted.

Source code example can be found here: https://github.com/abhinavmishra14/AlfrescoJMeterLoadTestPlugin/blob/master/src/com/jmeter/alfresco/...

You can take reference from that code and prepare the request similary. 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
ni0ni0s
Member II

Re: Internal error 500 on upload file from REST API

Jump to solution

Thanks for your help but in php i have errors.

{ "status" : { "code" : 500, "name" : "Internal Error", "description" : "An error inside the HTTP server which prevented it from fulfilling the request." }

i used:

$filename = "test.txt";

//The JSON data.
$jsonData = array(
"filedata"=> $filename,
"siteid"=> "defend",
"containerid"=> "documentLibrary",
"uploaddirectory"=> "uploadfolder",
"description"=> "its a description",
"contenttype"=> mime_content_type($filename),
"majorversion"=> "false",
"overwrite"=> "true"

);

abhinavmishra14
Advanced

Re: Internal error 500 on upload file from REST API

Jump to solution

I am not familier with PHP, someone who is famililier with PHP may provide more details, but would it be possible for you to post the full error log. Both from alfresco(alfresco.log) and share (share.log) by sending a request with the code you have.

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
ni0ni0s
Member II

Re: Internal error 500 on upload file from REST API

Jump to solution

share.log not showing error.

the requerst return this:
{ "status" : { "code" : 500, "name" : "Internal Error", "description" : "An error inside the HTTP server which prevented it from fulfilling the request." }, "message" : "09290256 Unexpected error occurred during upload of new content.", "exception" : "", "callstack" : [ ], "server" : "Community Early Access v6.0.0 (rbdba1485-b0) schema 10,200", "time" : "Oct 29, 2019 5:39:12 PM" }

and the alfresco.log returns

2019-10-29 17:41:19,060 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-14] Exception from executeScript: 09290257 Unexpected error occurred during upload of new content.
org.springframework.extensions.webscripts.WebScriptException: 09290257 Unexpected error occurred during upload of new content.
at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1124)
at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:519)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:464)
at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:587)
at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:656)
at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:428)
at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:308)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:399)
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:210)
at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.alfresco.module.aosmodule.service.ContextRootFilter.doFilter(ContextRootFilter.java:93)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:68)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2492)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.mozilla.javascript.JavaScriptException: ReferenceError: Unexpected error occurred during upload of new content. (classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js#519)
at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_24._c_main_6(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js:519)
at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_24.call(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:74)
at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_24._c_script_0(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js:523)
at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_24.call(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_24.call(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_repository_upload_upload_post_js_24.exec(classpath*:alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js)
at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:509)
at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:207)
at org.alfresco.repo.processor.ScriptServiceImpl.execute(ScriptServiceImpl.java:219)
at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:181)
at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:109)
at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1376)
at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)

abhinavmishra14
Advanced

Re: Internal error 500 on upload file from REST API

Jump to solution

Thanks let me review the log. Additonally can you also try to upload the same file via Any rest client such as postman and see what you get? use the same file and provide the same parameters. 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)