You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Sofiane Soulfly <sa...@hotmail.com> on 2014/12/22 13:23:45 UTC

Download file from Swift

Hello everybody,

after I uploaded successfully a text file to Swift, now I want download
that file into my file system.
I tried with ObjectApi.get but nothing was downloaded.
Thank you.

Regards,

SB

Re: Fwd: Re: Download file from Swift

Posted by Sofiane Soulfly <sa...@hotmail.com>.
Thank you Andrew, I resolved the problem.
For those who are interested, I first get the URI of the Object,
transform it to URL and then use FileUtils to copy the URL to a file.

Regards,

Sofiane.

On 23.12.2014 17:40, Andrew Gaul wrote:
> Try calling outputStream.flush() since it is a BufferedOutputStream.
> Generally easier to use the Guava helpers in these situations, e.g.,
> Files.asByteSink(File).writeFrom(InputStream), which handles resource
> management for you.  Also do not forget to close all the InputStream and
> OutputStream!
>
> On Tue, Dec 23, 2014 at 12:45:07PM +0100, Sofiane Soulfly wrote:
>> I tried your solution and the problem is that it creates a temp file,
>> which is empty. My objective is to download the file and its content.
>>
>>
>> -------- Forwarded Message --------
>> Subject: 	Re: Download file from Swift
>> Date: 	Mon, 22 Dec 2014 17:01:34 +0000
>> From: 	Everett Toews <ev...@RACKSPACE.COM>
>> Reply-To: 	user@jclouds.apache.org
>> To: 	user@jclouds.apache.org <us...@jclouds.apache.org>
>>
>>
>>
>> What version of jclouds are you using?
>>
>> Try this…
>>
>> ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
>> SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt”);
>>
>> // Write the object to a file
>> File file = File.createTempFile("uploadObjectFromFile", ".txt");
>> BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
>> ByteStreams.copy(swiftObject.getPayload().openStream(), outputStream);
>>
>> Everett
>>
>>
>> On Dec 22, 2014, at 6:23 AM, Sofiane Soulfly <sa...@hotmail.com> wrote:
>>
>>> Hello everybody,
>>>
>>> after I uploaded successfully a text file to Swift, now I want download
>>> that file into my file system.
>>> I tried with ObjectApi.get but nothing was downloaded.
>>> Thank you.
>>>
>>> Regards,
>>>
>>> SB
>>
>>


Re: Fwd: Re: Download file from Swift

Posted by Andrew Gaul <ga...@apache.org>.
Try calling outputStream.flush() since it is a BufferedOutputStream.
Generally easier to use the Guava helpers in these situations, e.g.,
Files.asByteSink(File).writeFrom(InputStream), which handles resource
management for you.  Also do not forget to close all the InputStream and
OutputStream!

On Tue, Dec 23, 2014 at 12:45:07PM +0100, Sofiane Soulfly wrote:
> I tried your solution and the problem is that it creates a temp file,
> which is empty. My objective is to download the file and its content.
> 
> 
> -------- Forwarded Message --------
> Subject: 	Re: Download file from Swift
> Date: 	Mon, 22 Dec 2014 17:01:34 +0000
> From: 	Everett Toews <ev...@RACKSPACE.COM>
> Reply-To: 	user@jclouds.apache.org
> To: 	user@jclouds.apache.org <us...@jclouds.apache.org>
> 
> 
> 
> What version of jclouds are you using?
> 
> Try this…
> 
> ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
> SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt”);
> 
> // Write the object to a file
> File file = File.createTempFile("uploadObjectFromFile", ".txt");
> BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
> ByteStreams.copy(swiftObject.getPayload().openStream(), outputStream);
> 
> Everett
> 
> 
> On Dec 22, 2014, at 6:23 AM, Sofiane Soulfly <sa...@hotmail.com> wrote:
> 
> > Hello everybody,
> > 
> > after I uploaded successfully a text file to Swift, now I want download
> > that file into my file system.
> > I tried with ObjectApi.get but nothing was downloaded.
> > Thank you.
> > 
> > Regards,
> > 
> > SB
> 
> 
> 

-- 
Andrew Gaul
http://gaul.org/

Fwd: Re: Download file from Swift

Posted by Sofiane Soulfly <sa...@hotmail.com>.
I tried your solution and the problem is that it creates a temp file,
which is empty. My objective is to download the file and its content.


-------- Forwarded Message --------
Subject: 	Re: Download file from Swift
Date: 	Mon, 22 Dec 2014 17:01:34 +0000
From: 	Everett Toews <ev...@RACKSPACE.COM>
Reply-To: 	user@jclouds.apache.org
To: 	user@jclouds.apache.org <us...@jclouds.apache.org>



What version of jclouds are you using?

Try this…

ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt”);

// Write the object to a file
File file = File.createTempFile("uploadObjectFromFile", ".txt");
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
ByteStreams.copy(swiftObject.getPayload().openStream(), outputStream);

Everett


On Dec 22, 2014, at 6:23 AM, Sofiane Soulfly <sa...@hotmail.com> wrote:

> Hello everybody,
> 
> after I uploaded successfully a text file to Swift, now I want download
> that file into my file system.
> I tried with ObjectApi.get but nothing was downloaded.
> Thank you.
> 
> Regards,
> 
> SB




Re: Download file from Swift

Posted by Sofiane Soulfly <sa...@hotmail.com>.
 I am using 1.8.x. I am testing your code now.
On 22.12.2014 18:01, Everett Toews wrote:
> What version of jclouds are you using?
>
> Try this…
>
> ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
> SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt”);
>
> // Write the object to a file
> File file = File.createTempFile("uploadObjectFromFile", ".txt");
> BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
> ByteStreams.copy(swiftObject.getPayload().openStream(), outputStream);
>
> Everett
>
>
> On Dec 22, 2014, at 6:23 AM, Sofiane Soulfly <sa...@hotmail.com> wrote:
>
>> Hello everybody,
>>
>> after I uploaded successfully a text file to Swift, now I want download
>> that file into my file system.
>> I tried with ObjectApi.get but nothing was downloaded.
>> Thank you.
>>
>> Regards,
>>
>> SB


Re: Download file from Swift

Posted by Everett Toews <ev...@RACKSPACE.COM>.
What version of jclouds are you using?

Try this…

ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER);
SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt”);

// Write the object to a file
File file = File.createTempFile("uploadObjectFromFile", ".txt");
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
ByteStreams.copy(swiftObject.getPayload().openStream(), outputStream);

Everett


On Dec 22, 2014, at 6:23 AM, Sofiane Soulfly <sa...@hotmail.com> wrote:

> Hello everybody,
> 
> after I uploaded successfully a text file to Swift, now I want download
> that file into my file system.
> I tried with ObjectApi.get but nothing was downloaded.
> Thank you.
> 
> Regards,
> 
> SB