File Upload Sorunu

View: New views
3 Messages — Rating Filter:   Alert me  

File Upload Sorunu

by Volk Tolk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Merhabalar
File upload konusunda bir iki sorunum var yardimci olabilirseniz
sevinirim.Tomahawk kullaniyorum.Sorunum aslinda file upload konusundan
ziyade upload edilen dosyanin servere kopyalanmasi ile ilgili.

-  Dosyalarý koplamak için kullandýðým metod ;
       public static void copyFile(File gelen, File hedef) throws
IOException {
        if(!hedef.exists()) {
            hedef.createNewFile();
        }
        InputStream in = null;
        OutputStream out = null;
        try {
         in = new  FileInputStream(gelen);
         out = new FileOutputStream(hedef);
         
         byte[] buf = new byte[1024];
         int len;
         while ((len = in.read(buf)) > 0) {
          out.write(buf, 0, len);
         }
        }
        finally {
         if(in != null) {
          in.close();
         }
         if(out != null) {
          out.close();
         }
        }
       }
   Ilk paramatre olarak file tipinde bir paramatre lazým fakat
backingBean deki gelen dosyanin tipi UploadedFile.Ne yaptiysam ne kadar
arastirdiysam uploadedFile i File a convert edemedim.UploadedFile i File
tipinie nasil cevirebilirim.Yada dosya kopyalama icin onerebileceginiz
baska bir yol varmi.

 - Serverin tam yolunu nasil ogrenebilirim.
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()
bu yontemle sadece sadece projenin ana klasorune ulasabiliyorum.Bana tam
yolu lazim.

- Son olarak, resimleri web deki konumunu kullanarak kendi projeme
kopyalabilirmiyim.Bir nevi File Upload in web versiyonu gibi..
 
   Simdiden tesekkurler...

 

       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

Re: File Upload Sorunu

by hasan tolak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Merhabalar

Saniyorum asagidaki aktardigim code parcasi
probleminizi cozer.

Kolayca gelsin

Hasan TOLAK

.....................................................
[CODE]
//UploadFileBean.java
import org.apache.log4j.Logger;
import
org.apache.myfaces.custom.fileupload.UploadedFile;
import java.io.*;


public class UploadFileBean {
    static Logger log =
Logger.getLogger(UploadFileBean.class.getName());
    public UploadFileBean() {
        super();
    }

    private boolean saveUploadedFile(UploadedFile
upFile, File targetFile) throws IOException {
        InputStream in = new BufferedInputStream(
                upFile.getInputStream());
        try {
            OutputStream out = new
BufferedOutputStream(
                    new FileOutputStream(targetFile));
            try {
                int b;
                while ((b = in.read()) != -1)
                    out.write(b);
            } finally {
                out.close();
            }
        } finally {
            in.close();

        }
        return true;
    }

    public boolean saveFileToDestDir(UploadedFile
upFile, File file) {
        try {
            if (file.exists()) file.delete();
            System.out.println(" saveFileToDestDir():
" + file.getAbsolutePath());
            saveUploadedFile(upFile, file);
            System.out.println(" saveFileToDestDir()
end: ");
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
}

[CODE]


[CODE]
ActionListener to handel the file upload action
public void addImageAListener(ActionEvent event) {
.....
    String addImgPath =
Utils.getAdvertisementImgRealPath();
    String fileName = "newFileName"  +
upFile.getName().substring(upFile.getName().lastIndexOf("."));
   
    File imgFile = new File(addImgPath, fileName);
    upFileBean.saveFileToDestDir(upFile, imgFile);

}
[CODE]
.....................................................


--- Volkan Terzi <volkan_te@...> wrote:

> Merhabalar
> File upload konusunda bir iki sorunum var yardimci
> olabilirseniz
> sevinirim.Tomahawk kullaniyorum.Sorunum aslinda file
> upload konusundan
> ziyade upload edilen dosyanin servere kopyalanmasi
> ile ilgili.
>
> -  Dosyalarý koplamak için kullandýðým metod ;
>        public static void copyFile(File gelen, File
> hedef) throws
> IOException {
>         if(!hedef.exists()) {
>             hedef.createNewFile();
>         }
>         InputStream in = null;
>         OutputStream out = null;
>         try {
>          in = new  FileInputStream(gelen);
>          out = new FileOutputStream(hedef);
>          
>          byte[] buf = new byte[1024];
>          int len;
>          while ((len = in.read(buf)) > 0) {
>           out.write(buf, 0, len);
>          }
>         }
>         finally {
>          if(in != null) {
>           in.close();
>          }
>          if(out != null) {
>           out.close();
>          }
>         }
>        }
>    Ilk paramatre olarak file tipinde bir paramatre
> lazým fakat
> backingBean deki gelen dosyanin tipi UploadedFile.Ne
> yaptiysam ne kadar
> arastirdiysam uploadedFile i File a convert
> edemedim.UploadedFile i File
> tipinie nasil cevirebilirim.Yada dosya kopyalama
> icin onerebileceginiz
> baska bir yol varmi.
>
>  - Serverin tam yolunu nasil ogrenebilirim.
>
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()

>
> bu yontemle sadece sadece projenin ana klasorune
> ulasabiliyorum.Bana tam
> yolu lazim.
>
> - Son olarak, resimleri web deki konumunu kullanarak
> kendi projeme
> kopyalabilirmiyim.Bir nevi File Upload in web
> versiyonu gibi..
>  
>    Simdiden tesekkurler...
>
>  
>
>        
> ---------------------------------
> Be a better friend, newshound, and know-it-all with
> Yahoo! Mobile.  Try it now.



      ___________________________________________________________
Yahoo! For Good helps you make a difference  

http://uk.promotions.yahoo.com/forgood/

[CODE]
//UploadFileBean.java
import org.apache.log4j.Logger;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import java.io.*;


public class UploadFileBean {
    static Logger log = Logger.getLogger(UploadFileBean.class.getName());
    public UploadFileBean() {
        super();
    }

    private boolean saveUploadedFile(UploadedFile upFile, File targetFile) throws IOException {
        InputStream in = new BufferedInputStream(
                upFile.getInputStream());
        try {
            OutputStream out = new BufferedOutputStream(
                    new FileOutputStream(targetFile));
            try {
                int b;
                while ((b = in.read()) != -1)
                    out.write(b);
            } finally {
                out.close();
            }
        } finally {
            in.close();

        }
        return true;
    }

    public boolean saveFileToDestDir(UploadedFile upFile, File file) {
        try {
            if (file.exists()) file.delete();
            System.out.println(" saveFileToDestDir(): " + file.getAbsolutePath());
            saveUploadedFile(upFile, file);
            System.out.println(" saveFileToDestDir() end: ");
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
}

[CODE]


[CODE]
ActionListener to handel the file upload action
public void addImageAListener(ActionEvent event) {
.....
    String addImgPath = Utils.getAdvertisementImgRealPath();
    String fileName = "newFileName"  + upFile.getName().substring(upFile.getName().lastIndexOf("."));
   
    File imgFile = new File(addImgPath, fileName);
    upFileBean.saveFileToDestDir(upFile, imgFile);

}
[CODE]

Re: File Upload Sorunu

by Volk Tolk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Cok tesekkur ediyorum Hasan Bey .Problem sayenizde cozuldu...
 Iyi Calismalar...

hasan tolak <h_tolak@...> wrote:                             Merhabalar
 
 Saniyorum asagidaki aktardigim code parcasi
 probleminizi cozer.
 
 Kolayca gelsin
 
 Hasan TOLAK
 
 .....................................................
 [CODE]
 //UploadFileBean.java
 import org.apache.log4j.Logger;
 import
 org.apache.myfaces.custom.fileupload.UploadedFile;
 import java.io.*;
 
 public class UploadFileBean {
     static Logger log =
 Logger.getLogger(UploadFileBean.class.getName());
     public UploadFileBean() {
         super();
     }
 
 private boolean saveUploadedFile(UploadedFile
 upFile, File targetFile) throws IOException {
         InputStream in = new BufferedInputStream(
                 upFile.getInputStream());
         try {
             OutputStream out = new
 BufferedOutputStream(
                     new FileOutputStream(targetFile));
             try {
                 int b;
                 while ((b = in.read()) != -1)
                     out.write(b);
             } finally {
                 out.close();
             }
         } finally {
             in.close();
 
 }
         return true;
     }
 
 public boolean saveFileToDestDir(UploadedFile
 upFile, File file) {
         try {
             if (file.exists()) file.delete();
             System.out.println(" saveFileToDestDir():
 " + file.getAbsolutePath());
             saveUploadedFile(upFile, file);
             System.out.println(" saveFileToDestDir()
 end: ");
         } catch (Exception ex) {
             ex.printStackTrace();
             return false;
         }
         return true;
     }
 }
 
 [CODE]
 
 [CODE]
 ActionListener to handel the file upload action
 public void addImageAListener(ActionEvent event) {
 .....
     String addImgPath =
 Utils.getAdvertisementImgRealPath();
     String fileName = "newFileName"  +
 upFile.getName().substring(upFile.getName().lastIndexOf("."));
     
     File imgFile = new File(addImgPath, fileName);
     upFileBean.saveFileToDestDir(upFile, imgFile);
 
 }
 [CODE]
 .....................................................
 
 --- Volkan Terzi <volkan_te@...> wrote:
 
 > Merhabalar
 > File upload konusunda bir iki sorunum var yardimci
 > olabilirseniz
 > sevinirim.Tomahawk kullaniyorum.Sorunum aslinda file
 > upload konusundan
 > ziyade upload edilen dosyanin servere kopyalanmasi
 > ile ilgili.
 >
 > -  Dosyalarý koplamak için kullandýðým metod ;
 >        public static void copyFile(File gelen, File
 > hedef) throws
 > IOException {
 >         if(!hedef.exists()) {
 >             hedef.createNewFile();
 >         }
 >         InputStream in = null;
 >         OutputStream out = null;
 >         try {
 >          in = new  FileInputStream(gelen);
 >          out = new FileOutputStream(hedef);
 >          
 >          byte[] buf = new byte[1024];
 >          int len;
 >          while ((len = in.read(buf)) > 0) {
 >           out.write(buf, 0, len);
 >          }
 >         }
 >         finally {
 >          if(in != null) {
 >           in.close();
 >          }
 >          if(out != null) {
 >           out.close();
 >          }
 >         }
 >        }
 >    Ilk paramatre olarak file tipinde bir paramatre
 > lazým fakat
 > backingBean deki gelen dosyanin tipi UploadedFile.Ne
 > yaptiysam ne kadar
 > arastirdiysam uploadedFile i File a convert
 > edemedim.UploadedFile i File
 > tipinie nasil cevirebilirim.Yada dosya kopyalama
 > icin onerebileceginiz
 > baska bir yol varmi.
 >
 >  - Serverin tam yolunu nasil ogrenebilirim.
 >
 FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()
 >
 > bu yontemle sadece sadece projenin ana klasorune
 > ulasabiliyorum.Bana tam
 > yolu lazim.
 >
 > - Son olarak, resimleri web deki konumunu kullanarak
 > kendi projeme
 > kopyalabilirmiyim.Bir nevi File Upload in web
 > versiyonu gibi..
 >  
 >    Simdiden tesekkurler...
 >
 >  
 >
 >        
 > ---------------------------------
 > Be a better friend, newshound, and know-it-all with
 > Yahoo! Mobile.  Try it now.
 
 __________________________________________________________
 Yahoo! For Good helps you make a difference  
 
 http://uk.promotions.yahoo.com/forgood/
     
                                       
[CODE]
//UploadFileBean.java
import org.apache.log4j.Logger;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import java.io.*;


public class UploadFileBean {
    static Logger log = Logger.getLogger(UploadFileBean.class.getName());
    public UploadFileBean() {
        super();
    }

    private boolean saveUploadedFile(UploadedFile upFile, File targetFile) throws IOException {
        InputStream in = new BufferedInputStream(
                upFile.getInputStream());
        try {
            OutputStream out = new BufferedOutputStream(
                    new FileOutputStream(targetFile));
            try {
                int b;
                while ((b = in.read()) != -1)
                    out.write(b);
            } finally {
                out.close();
            }
        } finally {
            in.close();

        }
        return true;
    }

    public boolean saveFileToDestDir(UploadedFile upFile, File file) {
        try {
            if (file.exists()) file.delete();
            System.out.println(" saveFileToDestDir(): " + file.getAbsolutePath());
            saveUploadedFile(upFile, file);
            System.out.println(" saveFileToDestDir() end: ");
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
}

[CODE]


[CODE]
ActionListener to handel the file upload action
public void addImageAListener(ActionEvent event) {
......
    String addImgPath = Utils.getAdvertisementImgRealPath();
    String fileName = "newFileName"  + upFile.getName().substring(upFile.getName().lastIndexOf("."));
   
    File imgFile = new File(addImgPath, fileName);
    upFileBean.saveFileToDestDir(upFile, imgFile);

}
[CODE]

       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.