Skip to Content
avatar image
Former Member

File Upload & Download getByteArrayFromResourcePath

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    May 09, 2007 at 08:10 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • avatar image
    Former Member
    May 09, 2007 at 08:13 AM

    Hai,

    This blog may help to you

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

    Regards,

    Naga

    Add comment
    10|10000 characters needed characters exceeded