pluquload jquery plugin - поврежденный файл после загрузки

Я использую Plupload для загрузки файлов на один сервер, процесс загрузки работает хорошо, но когда я открыл файл (например, docx), он говорит, что он поврежден и содержит дополнительные данные (я думаю, что это какой-то заголовок из xmlhttprequest).

Вы можете увидеть дополнительные данные в этой ссылке -> http://prntscr.com/4hl5lo

Мой код:

Сторона клиента:

AJS.$("input#edit-template-file").replaceWith('<div id="container"> <a id="pickfiles" href="javascript:;">[Select files]</a> <a id="uploadfiles" href="javascript:;">[Upload files]</a> </div>');

    var uploader = new plupload.Uploader({
        runtimes : 'html5,flash,silverlight,html4',

        browse_button : 'pickfiles', // you can pass in id...
        container: document.getElementById('container'), // ... or DOM Element itself

        url : '[my url]',
        multi_selection: false, 
        send_file_name: false,
        chunk_size: 0,
        filters : {
            max_file_size : '100mb',
            mime_types: [
                {title : "Doc files", extensions : "docx,docm,dotx,dotm,odt,rtf"}
            ]
        },

        // Flash settings
        flash_swf_url : 'Moxie.swf',

        // Silverlight settings
        silverlight_xap_url : 'Moxie.xap',


        init: {
            PostInit: function() {
                document.getElementById('uploadfiles').onclick = function() {
                    uploader.start();
                    return false;
                };
            },
            BeforeUpload: function(up, file) {
                // Called right before the upload for a given file starts, can be used to cancel it if required
                delete up.settings.multipart_params; //i have tried this to remove the additional data written in the file but without sucess
                console.log('[BeforeUpload]', 'File: ', file);
            },
            UploadProgress: function(up, file) {
                AJS.progressBars.update("#templateBar", file.percent);
            },
            FileUploaded: function(up, file, info) {
                console.log(info.response);
                if (info.response != '') {
                    AJS.$(fileFieldId).val(info.response);
                    AJS.$("div#container").attr( 'name', file.name );
                    setSubmitState(false);
                }
            },

            Error: function(up, err) {
                document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
            }
        }
    });

    uploader.init();

Серверная часть (Java):

  public Response createFile(InputStream is) throws IOException {

    final String templatesPath = buildTemplatesPath();
    final File templatesDir = new File(templatesPath);
    if (!templatesDir.exists()) {
        templatesDir.mkdir();
    }
    final String tmpPath = buildTMPPath();
    final File tmpDir = new File(tmpPath);
    if (!tmpDir.exists()) {
        tmpDir.mkdir();
    }

    final String fileId = UUID.randomUUID().toString();

    try {
        writeToFile(is, buildFilePath(fileId));
    } catch (Exception e) {
        logger.error("Unable to write template", e);
        return Response.status(500);
    }

    return Response.status(200);

}

  private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) throws Exception {

    try {
        final OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
        int read = 0;
        final byte[] bytes = new byte[1024];
        while ((read = uploadedInputStream.read(bytes)) != -1) {
            out.write(bytes, 0, read);
        }
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.error("Unable write file", e);
        throw e;
    }
}

Я изучал эту тему и нашел файл, в котором Plupload записывает дополнительный заголовок в xmlhttprequest ( https://github.com/moxiecode/moxie/blob/master/src/flash/src/com/XMLHttpRequest.as), но я не могу удалить эти данные, любая помощь?

1 ответ

Ничто не повреждено, но вы должны обновить все сценарии href scipt и css, которые добавлены в img_upload.php

Я имею в виду, что файл CSS и файл jquery, включающие их путь, заменяются путем загрузки файлов jquery и css, в противном случае проверьте плагин, заменив jquery и css на их онлайн-путь, где хранилище файлов затем после проверки плагина

Другие вопросы по тегам