1

Currently, I am writing xml file on local directory using XMLOutputFactory which accept OutputStream as a parameter. But Now I need to write xml file to AWS S3 without writing on local. I don't have local directory access.

But I am not getting "How I can write xml file to AWS S3?".

Here is my code which write xml in local directory.

File file = new File(storeFilename);
DataOutputStream stream = null;
stream = new DataOutputStream(new FileOutputStream(file));
// Create new instance of XML straem writer
XMLOutputFactory inputFactory = XMLOutputFactory.newInstance();

try {
    XMLStreamWriter writer = inputFactory.createXMLStreamWriter(
                graphMLOutputStream, "UTF8");

    writer.writeStartDocument();
    writer.writeStartElement(GRAPHML);
    writer.writeAttribute(XMLNS, GRAPHML_XMLNS);
   }

I know how to put files on AWS S3 using PutObjectRequest() by giving file name or inputstream as a parameter.

// send request to S3 to create folder
PutObjectRequest putobjreq = new PutObjectRequest(
                CAWSConstants.BUCKETNAME, file.getName(), file);            
// put graphml file to aws
s3Client.putObject(putobjreq);   

But I don't know how to covert xml in to inputstream using xmlWriter. Which I can sent to PutObjectRequest.

Please give me hint or reference.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

1 Answers1

0

Instead of a FileOutputStream you should be able to use a ByteArrayOutputStream. Then refer to How to upload a Java OutputStream to AWS S3.

Community
  • 1
  • 1
jzonthemtn
  • 3,344
  • 1
  • 21
  • 30