Skip to content

File upload in browser - use PUT if possible #4380

Description

@DeepDiver1975

Our file upload javascript component is capable of using PUT for file upload
https://github.com/blueimp/jQuery-File-Upload/wiki/Options

Using PUT has some advantages over the existing POST:
The PHP code will be trigger as soon as the first few kbs arrived th server.
In contrary in case of POST the web server will first receive the whole file and trigger the PHP code after the upload has been finished.

Why is this a better approach:

  • quota and other checks can be performed right in the beginning
  • follow up processing can benefit from stream e.g. push data to external file systems, encrypt on the fly (?)

From my understanding this is why WebDAV uses PUT for file upload as well.

@karlitschek @danimo @dragotin @icewind1991 @butonic @blizzz @schiesbn @bartv2 @bantu @ringmaster

I'm summoning you all because I'd like to know any impact on any component you are working on if you see any issues with this approach.

THX

Activity

  1. danimo commented on Aug 9, 2013

    @danimo
    Contributor

    Next advantage: Once we switch to a PUT-based approach, we can implement file chunking, too. This means that for all practical purposes (with the unfortunate exceptions of the infamous IE 8 and 9), we do not have to deal with stupid PHP upload limitations. This alone will save us quite some headaches in the future.

  2. icewind1991 commented on Aug 9, 2013

    @icewind1991
    Contributor

    No need for that, there isn't a restriction on the size of PUT uploads in the first place

  3. danimo commented on Aug 9, 2013

    @danimo
    Contributor

    @icewind1991 good point. still, chunks could be useful for resuming big downloads.

  4. butonic commented on Aug 9, 2013

    @butonic
    Contributor

    There is an in depth description at http://stackoverflow.com/questions/12005790/how-to-receive-a-file-via-http-put-with-php

    Don't know if we have to manually cut the headers from the body. Will take a look along with the client side changes.

  5. DeepDiver1975 commented on Aug 9, 2013

    @DeepDiver1975
    ContributorAuthor
  6. blizzz commented on Aug 12, 2013

    @blizzz
    Contributor

    Will apps that require the whole file behave properly? Like encryption or versioning for example.

  7. DeepDiver1975 commented on Aug 12, 2013

    @DeepDiver1975
    ContributorAuthor

    Will apps that require the whole file behave properly? Like encryption or versioning for example.

    From my understanding all file operations within ownCloud work on streams - if not we need to change this.
    We cannot expect to have enough server RAM to process e.g. 10 user requests on a 4 GB file all in RAM.

    @icewind1991 @schiesbn

  8. bartv2 commented on Aug 18, 2013

    @bartv2
    Contributor

    Also now we have auth via session maybe we can use the webdav interface to do uploading of files?

  9. LukasReschke commented on Oct 30, 2014

    @LukasReschke
    Contributor

    Adding to technical debt. Would make very much sense. @MorrisJobke Does something similiar in his music app for reading files.

  10. MorrisJobke commented on Oct 30, 2014

    @MorrisJobke
    Contributor

    I just use get because I don't need PUT nowadays, but we should enforce using our own APIs and the WebDAV is the most stable of them ;)

  11. DeepDiver1975 commented on Mar 2, 2015

    @DeepDiver1975
    ContributorAuthor

    this will be implemented once we move over to use webdav in the files apps #12353

  12. PVince81 commented on Jun 9, 2015

    @PVince81
    Contributor

    I suggest we keep this ticket as a subticket of #12353.

    Implementing PUT is already a challenging task, especially in regards to cross-browser compatibility. So it makes sense to have this implemented in its own PR.

  13. 13 remaining items

  14. PVince81 commented on Dec 17, 2015

    @PVince81
    Contributor

    Interesting, the blueimp uploader would POST to this URL with the IE iframe fallback:

    192.168.56.102 - - [17/Dec/2015:18:17:06 +0100] "POST /owncloud/remote.php/webdav/modern.IE.1024x768.jpg?_method=PUT HTTP/1.1" 501 247 "http://192.168.56.1/owncloud/index.php/apps/files/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
    

    This means that in theory instead of keeping "ajax/upload.php" we could simply write a Sabre plugin that processes this POST and internally plugs with the PUT logic. 😄

  15. PVince81 commented on Feb 12, 2016

    @PVince81
    Contributor

    Still needs a bit more work for the PR #21237, moving to 9.1

  16. modified the milestones: , on Feb 12, 2016
  17. MTRichards commented on Apr 1, 2016

    @MTRichards
    Contributor

    Estimation: 1 week

  18. modified the milestones: , on Jun 9, 2016
  19. PVince81 commented on Jun 21, 2016

    @PVince81
    Contributor

    Someone raised a ticket for PUT chunking. Since we didn't have a dedicated ticket, let's use this one #25181

  20. PVince81 commented on Sep 8, 2016

    @PVince81
    Contributor

    Hmm, but when overwriting a file we are using POST on collection with "Add-Member" here https://tools.ietf.org/html/rfc5995#page-5 here https://github.com/owncloud/core/blob/master/apps/dav/lib/Connector/Sabre/FilesPlugin.php#L440.
    This is used when the conflict dialog appears and the user wants to keep old files, so we use "Add-Member" to suggest a name for the server. The server then append "(2)", "(3)" or whatever depending on existing files.

    Drawback is that we still use POST and would suffer from limitations.
    Reopening to reconsider this.

    Also this approach is not compatible with new chunking, so might still need a client-side only approach that looks like this:

    1. PUT file "test.dat"
    2. Server answers with 409 conflict
    3. User resolves conflict in dialog by ticking both "New files" and "Already existing file"
    4. Client checks current file list (which might not be up to date) to add a "(2)" in the name: "test (2).dat"
    5. Client uploads "test (2).dat"
    6. Server answers with 409 conflict again because someone concurrently created "test (2).dat"
    7. Client tries again with next "test (3).dat", etc.
  21. PVince81 commented on Sep 9, 2016

    @PVince81
    Contributor

    Fix for autorename is here: #26078
    This removes POST completely for uploads.

  22. lock commented on Aug 3, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  23. locked as resolved and limited conversation to collaborators on Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions