cancel
Showing results for 
Search instead for 
Did you mean: 

Java Backed Web Script : Problem uploading documents

oskarlanda
Champ in-the-making
Champ in-the-making
Hi,

I have a java backed WebScript  for upload documents, implementing this code:

FormField formField = ((WebScriptServletRequest) req).getFileField(fileName.toString());

I was using Alfresco 3.4 Enterprise, and  now I have upgrade to 4.0.c


Now the casting raises an error because the request type is: org.alfresco.repo.web.scripts.RepositoryContainer$BufferedRequest that inherits from  WebScriptRequest, but not from  WebScriptServletRequest.

any ideas ?

Thank's in advance.
3 REPLIES 3

mitpatoliya
Star Collaborator
Star Collaborator
What information exactly you are trying to extract from that piece of code.
I guess you need to look into new APIs inside WebScriptRequest Object

rivarola
Champ on-the-rise
Champ on-the-rise
For those running into the same problem, here is one solution :

FormField formField = ((WebScriptServletRequest)((WrappingWebScriptRequest) req).getNext()).getFileField(fileName.toString());

kofwhgh
Champ in-the-making
Champ in-the-making
Hi!

I used this source from alfresco 4.0

public Map<String, Object> upload(WebScriptRequest request) throws Exception {
      Map<String, Object> model = new HashMap<String, Object>();
     
      WebScriptServletRequest webScriptServletRequest = null;
      WebScriptRequest current = request;

      do {
         if(current instanceof WebScriptServletRequest) {
            webScriptServletRequest = (WebScriptServletRequest) current;
            current = null;
         } else if(current instanceof WrappingWebScriptRequest) {
            current = ((WrappingWebScriptRequest) request).getNext();
         } else {
            current = null;
         }
      } while (current != null);
     
      // this parameter in getFileField method is name of input element ex(input type="file" id="filedata" name="filedata" )
      FormField formField = webScriptServletRequest.getFileField("filedata");
      File file = TempFileProvider.createTempFile("alfresco", ".upload");
      IOUtil.copyCompletely(formField.getInputStream(), new FileOutputStream(file));

      return model;
   }

good day