简体   繁体   中英

Size of the file is changing after upload in spring

I am trying to upload an apk file in my local spring java web application, but the size of the file is getting changed after its uploaded as a result of which checksum is failing.

basically the size of the file on disk is different than the size of the file I receive in my application.

I am completely clueless, I am not sure how to go on debugging this.

PS: the temp file(tmp folder) which gets created during uploading has increased size than the one I originally upload.

code :

@RequestMapping(value = "/app", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA)
public Application upload(@RequestParam(value = "apkFile", required=false) MultipartFile apkFile, 
                          @RequestParam(value = "iconFile", required=false) MultipartFile iconFile, 
                          @RequestParam Map<String, String> params, HttpServletRequest request, 
                          Authentication authentication) {
    //process
}

Dependencies I use

<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.2</version>
</dependency>

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.5</version>
</dependency>

Html code I use :

Upload File Request Page

    <form method="POST"
        action="http://localhost:8080/devicemanagement_administration/admin/api/v1/application/app"
        enctype="multipart/form-data">
        type(binary,icon or screenshot): <input type="text" name="contentType"><br />
         tenantId(ibm or google): <input type="text" name="tenantId"><br />
        <br /> platform(android or ios): <input type="text" name="platform"><br />
        File to upload: <input type="file" id="apkFile" name="apkFile"><br /> content
        <br /> <input type="submit" value="Upload"> Press here to
        upload the file!
    </form>

</body>
</html>

PS:i tried uploading text and json files, the size doesnt change after uploading.. only most apks are causing issues.

I finally figured out what was the issue,

I had put a logging filter to this application which would alter the request in that logging filter. Removed the part where the request is altered. working fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM