cancel
Showing results for 
Search instead for 
Did you mean: 

File Upload & Download getByteArrayFromResourcePath

Former Member
0 Kudos

anyone can help me on this

from the coding , you can see that the getByteArrayFromResourcePath() is get from the local disk drive...

if i save the file in binary format in database , how to i retrieve back the file

pls advice


public void wdDoInit()
{
    //@@begin wdDoInit()
IWDAttributeInfo attInfo=wdContext.getNodeInfo().getAttribute(IPrivateDownView.IContextElement.SOURCE);
IWDModifiableBinaryType binaryType=(IWDModifiableBinaryType)attInfo.getModifiableSimpleType();
binaryType.setFileName(DownView.FILE_NAME);
binaryType.setMimeType(WDWebResourceType.XLS);
try{
//String resourcePath=WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),DownView.FILE_NAME);
String resourcePath="C:\tmnet.xls";
wdContext.currentContextElement().setSource(this.getByteArrayFromResourcePath(resourcePath));
//}catch(WDAliasResolvingException e){
//wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(),true);
}catch(Exception e){
throw new WDRuntimeException(e);	
}
//@@end
}

//@@begin others
private byte[] getByteArrayFromResourcePath(String resourcePath)
throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream(new File(resourcePath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int length;
byte[] part = new byte[10 * 1024];
while ((length = in.read(part)) != -1) {
out.write(part, 0, length);
}
in.close();
return out.toByteArray();
}

private static final String FILE_NAME = "tmnet.xls";
//@@end

Message was edited by:

yzme yzme

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hai,

This blog may help to you

/people/anilkumar.vippagunta2/blog/2007/02/20/reading-and-writing-images-from-sqlserver-in-webdynpro

Regards,

Naga

sid_sunny
Contributor
0 Kudos

Hi Yzme,

This path is on your WAS and not of your local machine (unless you have everything local) and from which database are you talking of saving and retrieving from. Kindly specify.

Regards

Sid

Former Member
0 Kudos

the file is located in drive c:\tmnet.xls in WAS...

I am using MSSQL 2000

the file is store in byte[]

sid_sunny
Contributor
0 Kudos

Hi Yzme,

Besides the blog suggested by Naga you can refer to this too.

Regards

Sid

Former Member
0 Kudos

Hi,

Please tell me how to upload file from local machine.

I have successfully uploaded files by using File Upload UI element where I am able to select the required file.

Now I have a requirement of picking up a file from desktop using the code.

If I am simply giving the path "C:
Folder\file.txt", it is searching on server.

Thanks!!

Anubha