DAM file InputStream is not reflecting original content in document management systems like Dropbox | Community
Skip to main content
ArpitBora
New Participant
September 18, 2017
Solved

DAM file InputStream is not reflecting original content in document management systems like Dropbox

  • September 18, 2017
  • 14 replies
  • 6024 views

Hi All,

Is there any way to upload a file directly from AEM DAM location like "/content/dam/myFiles" to document management system like Dropbox.

I referred this article http://www.tothenew.com/blog/making-dropbox-documents-available-in-aem/ for "Making Dropbox documents available in AEM".

Using above article I'm able to download dropbox file into AEM DAM successfully, now I'm trying to upload a file from DAM location to Dropbox.

I referred the Dropbox Java Core API v2 as well and found following code for uploading a file to Dropbox :

// Upload "test.txt" to Dropbox

InputStream inputStream = new FileInputStream("test.txt");

FileMetadata metadata = client.files().uploadBuilder("/test.txt").uploadAndFinish(inputStream);

In above code, InputStream is required to upload a file into Dropbox, which is I'm able to retrieve using Asset Interface method getOriginal()

...

Asset asset = resource.adaptTo(Asset.class);

Resource original = asset.getOriginal();

InputStream inputStream = original.adaptTo(InputStream.class);

...

Here when I'm passing this retrieved InputStream from AEM into Dropbox upload method "uploadAndFinish(inputStream)", It is not uploading the file with its original form but as encrypted or corrupted form.

Please provide your suggestion and answers.

I'm Using AEM 6.2 instance.

Thanks,
Arpit Bora

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ArpitBora

Thanks everyone for spending your valuable time on this issue,

Using Dropbox REST call to "https://content.dropboxapi.com/1/files_put/auto/<path>?param=val " endpoint using ByteArrayPartSource class of "org.apache.commons.httpclient.methods.multipart.ByteArrayPartSource" package solve my issue,

...

ByteArrayPartSource source = new ByteArrayPartSource(file.getName(),IOUtils.toByteArray(inputStream));

...

Now I'm able to upload file succesfull to Dropbox

Thanks and Regards,

Arpit Bora

14 replies

ArpitBora
ArpitBoraAuthor
New Participant
September 19, 2017

Thanks kautuksahni for the suggestion, I tried your piece of code the output is same.

ArpitBora
ArpitBoraAuthor
New Participant
September 19, 2017

There is no error Veena_07 my code executing successfully, the issue is with InputStream. The InputStream is uploading the file in Dropbox with encrypted or corrupted form.

kautuk_sahni
Employee
September 19, 2017

Moving this question to AEM assets Topic.

But please have a look at this:-InputStream object to read from DAM Asset

// An Asset doesn't have an InputStream per se. You need to use one of the renditions.

querybuilder = resource.getResourceResolver().adaptTo(QueryBuilder.class);

Query query = querybuilder.createQuery(PredicateGroup.create(map), session);

SearchResult result = query.getResult();

for (Hit hit : result.getHits())

     { try

          { Resource assetResource = hit.getResource();

            Asset asset = assetResource.adaptTo(Asset.class); // you probably need a null check here...

            Rendition original = asset.getOriginal();

            if (original != null)

                { // it is rare, but some assets might not have an original rendition

                   InputStream stream = original.getStream(); // do something with the stream

                }

          } catch (Exception e) { e.printStackTrace();

           }

}

More ways that I found out [not tested]:- Adobe CQ/Adobe AEM: How to read an external file in CQ

PS:- I am not an expert in assets side, just sharing what I found in the forums.

~kautuk

Kautuk Sahni
VeenaVikraman
New Participant
September 18, 2017

What error are you getting ? Can you log the data on a log file and check if you are able to fetch the correct information ?