weixin_39596835
weixin_39596835
2020-12-29 04:11

Empty Upload Response - Using BlueImp

Hello,

I am using blueimp. After following the setup documentation I can upload files and also view them on my local disc. However, blueimp doesn't show me that the file has been uploaded successfully. While searching for the potential reason I discovered that the upload-response is empty. Afaik, blueimp requires that the response contains a JSON-encoded state message according to https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#using-jquery-file-upload-ui-version-with-a-custom-server-side-upload-handler

Do I have to take care of that on myself? Or might the error be somewhere else?

该提问来源于开源项目:1up-lab/OneupUploaderBundle

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

9条回答

  • weixin_39818521 weixin_39818521 4月前

    You're right. Currently we have an EmptyResponse object in use. On the other hand, the BlueimpErrorHandler requires the base files key, as it appends the error to it. It would therefore make sense to add a new BlueimpResponse class, which has at least a addFile method. This even though we can only add the keys name and size. url, thumbnailUrl, and deleteUrl depend on your implementation.

    The only problem I see is that this is in any case a BC break for those who implemented it by hand so far. Any clue for versioning?

    点赞 评论 复制链接分享
  • weixin_39596835 weixin_39596835 4月前

    Hi sheeep,

    thanks for your reponse. Since I am completely new to the topic, I am unfortunately not able to get the full picture of your answer.

    What I understand is, that the logic to generate the response is currently my job as a user of the library. If yes, what are the points to tackle in order to do so? Question is, what do I have to implement and how do I connect it to the OneupUploaderBundle?

    点赞 评论 复制链接分享
  • weixin_39818521 weixin_39818521 4月前

    Hi

    You can follow the documentation and write something like this:

     php
    namespace Acme\HelloBundle\EventListener;
    
    use Oneup\UploaderBundle\Event\PostPersistEvent;
    
    class UploadListener
    {
        public function onUpload(PostPersistEvent $event)
        {
            $file = $event->getFile();
            $response = $event->getResponse();
    
            $url = ...;
            $deleteUrl = ...;
    
            $response['files'] = [
                'name' => $file->getFilename(),
                'size' => $file->getSize(),
                'url' => $url,
                'deleteUrl' => $deleteUrl,
                'deleteType' => 'DELETE'
            ];
        }
    }
    

    Note: This is untested.

    Be sure to register your UploaderListener as mentioned in here.

    I'll think about introducing a new return type which could automate a subset of the keys needed. But I'm afraid this implies bumping to a new major version, as it breaks already implemented solutions.

    点赞 评论 复制链接分享
  • weixin_39796363 weixin_39796363 4月前

    This is exactly how I implemented the Listener with Bluimp upload frontend. I used $file->getFile() instead, getFileName throw an error. The problem I noticed with this implementation is that with chunked upload and and multiple files upload and PosUpload event, event->getFile() return only the last file processed and not only an array of files. Is this a mistake I made or maybe it's due to the bluimp implementation ?

    点赞 评论 复制链接分享
  • weixin_39818521 weixin_39818521 4月前

    I used $file->getFile() instead, getFileName throw an error.

    $file after $event->getFile() should contain a File or a Gaufrette\File instance, therefore I can't see how a getFile method possibly return another file. Just check the class of the object returned by $event->getFile() and perform the corresponding methods on it.

    event->getFile() return only the last file processed and not only an array of files.

    Actually this should not be the case. The event is fired for each file uploaded in a request. Normally, the jQuery File Uploader triggers a request for each file you want to upload. You can configure it to upload multiple files at once. If you do so, the PostUploadEvent is still dispached once for each individual file.

    The problem I noticed with this implementation is that with chunked upload and and multiple files upload and PosUpload event [...]

    You mean like: Using chunked uploads and multiple files per request? I don't think this could possibly make any sense, because chunked uploads covers the use case, when one file is too big to handle by one request.

    点赞 评论 复制链接分享
  • weixin_39601929 weixin_39601929 4月前

    The event is fired for each file uploaded in a request.

    Sorry for interfering, but the above is not true. It is only fired for the reassembled file. EDIT My bad, it is fired for each file in multi-file requests. In case of chunks for the reassembled file.

    You mean like: Using chunked uploads and multiple files per request?

    And is correct, this is not possible, see the note here for how the behaviour if you try to set it up like that.

    The response for the frontend does not HAVE to follow that structure, it is dependant on your template.

    点赞 评论 复制链接分享
  • weixin_39818521 weixin_39818521 4月前

    Sorry for interfering, but the above is not true. It is only fired for the reassembled file.

    Correct. Lets break that down:

    If you're using chunked uploads, the PostUploadEvent is fired after the last chunk was uploaded, and the file got reassembled. You can also listen to a PostChunkUpload event, which is dispatched after a chunk file has been uploaded.

    thx

    点赞 评论 复制链接分享
  • weixin_39796363 weixin_39796363 4月前

    Ehy, again, you're right :+1: I'm using $file->getName() because $file it's of Gaufrette\File type, getFilename() came from File.

    thank you again Federico

    点赞 评论 复制链接分享
  • weixin_39818521 weixin_39818521 4月前

    No worries. I'm closing this in favor of the comment previously made:

    The response for the frontend does not HAVE to follow that structure, it is dependant on your template.

    I'm happy to implement any feature as long as it does not exclude those who created there very own frontend. :)

    点赞 评论 复制链接分享

相关推荐