Forum Stats

  • 3,874,563 Users
  • 2,266,761 Discussions
  • 7,911,898 Comments

Discussions

How to upload file from ADF using <af:input> component in Webcenter imaging

Sanjeev-OFM
Sanjeev-OFM Member Posts: 411 Bronze Badge

Hello Friends,


We have to upload a file from Webcenter imaging from ADF application but when using the <af:inputFile> component we are unable to get the filepath which is required to upload the file in imaging using the imaging api.


Kindly suggest how i can get the filepath in adf application to fulfil the requirement.

Thanks

Sanjeev

Best Answer

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,923 Red Diamond
    Answer ✓

    You don't need to use the file to create a DataHander object. You can use

               UploadedFile file = (UploadedFile)valueChangeEvent.getNewValue();
               // get a byte array from the stream and create a DataHandler from it
               byte[] byteArray=org.apache.commons.io.IOUtils.toByteArray(file.getInputStream());
               DataHandler dataHandler = new DataHandler(byteArray,"application/octet-stream");
    

    to create a DataHandler from the uploadFile.


    Timo

Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,923 Red Diamond

    Which filepath?

    From the ADF application, there is no file path, just data.

    What exactly is Webcenter imaging?

    Timo

  • Sanjeev-OFM
    Sanjeev-OFM Member Posts: 411 Bronze Badge
    edited Aug 9, 2022 7:33AM

    Hi Timo,

    I'm referring this document to upload the document from adf Web application to webcenter Imaging where it's required the filepath but as you mentioned I'm also able to get the file content instead of file path to upload the document in imaging.

    https://docs.oracle.com/en/middleware/webcenter/content/12.2.1.4/develop-image/creating-documents.html#GUID-12E170EB-2462-4F3A-8C89-35EC485945B8

    Please guide is there any possibility to get the filepath using af:input file or need to use any other component.


    Thanks

    Sanjeev

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,923 Red Diamond

    Why do you need the filepath?

    In the sample the filepath is used to load the data from the file. You get that data from an inputfile, so no filepath is needed.


    timo

  • Sanjeev-OFM
    Sanjeev-OFM Member Posts: 411 Bronze Badge

    Hi Timo,


    Thanks for the update but actually when we are calling this code snapshot during creating the object of DataHandler class internally it's calling the FileDataSource class object which take only two parameters to create the Object either java.io.File Object or filePath as String parameters.

    Kindly suggest on that.

        // Upload document content
                String fileName = "C:/PathToImages/invoice1234.tif";
                DataHandler fileData = new DataHandler(new FileDataSource(fileName));
                String uploadToken = docContentService.uploadDocument(fileData, 
                 "invoice1234.tif");
    

    package javax.activation;

    public class FileDataSource

      implements javax.activation.DataSource

    {

      // Constructors

       public FileDataSource(java.io.File p1) { }

      public FileDataSource(java.lang.String p1) { }

    }

    Thanks

    Sanjeev

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 38,923 Red Diamond
    Answer ✓

    You don't need to use the file to create a DataHander object. You can use

               UploadedFile file = (UploadedFile)valueChangeEvent.getNewValue();
               // get a byte array from the stream and create a DataHandler from it
               byte[] byteArray=org.apache.commons.io.IOUtils.toByteArray(file.getInputStream());
               DataHandler dataHandler = new DataHandler(byteArray,"application/octet-stream");
    

    to create a DataHandler from the uploadFile.


    Timo

  • Sanjeev-OFM
    Sanjeev-OFM Member Posts: 411 Bronze Badge

    Hi Timo,


    Thanks alot for the information, It's worked. Issue got resolved.


    Thanks Again

    Sanjeev