Uploading files using multipart/form-data
Posted on 2003-03-27
I want to upload files usign a servlet through multipart/form-data. I have written code which gets the input stream and parses the top headers till the actual file contents starts and then the boundary header at the bottom. i also get the file name from the header which i am using it to store the file to the server. I am able to upload a txt file and bmp file and .java and .class files but .gif and .jpg files are not uploaded as it should be. when i upload gif or jpg file and open it both opens but the images are incompleted and blurred respectively there is no error shown when i try to open these files. When i upload a Pdf files it uploads but the pages are blank. when i upload the pdf files without parsing the contents i.e., i read the whole inputstream as byte and writting the whole stream as byte then the file is uploaded perfectly. I know there are ready codes available but i want to write one of my own. If some body can tell me what is going wrong it will be a great help for me. corrently i am reading and writting in bytes or if i could get the logic to parse the content with out disturbing the bytes so that i can upload any file perfectly i will be amazing...Thanks.