Skip to content

Conversation

@snipe
Copy link
Member

@snipe snipe commented May 19, 2025

This changes the behavior of the uploads API to allow for better responses when a file is invalid, and better responses to show which files were successfully uploaded.

Now, if you upload files where some fail due to validation, you will still see the ones that succeed:

✨snipe@chodeblossom✨ snipe-it  (rework_bulk_api) $ curl --insecure --request POST --url https://snipe-it.test/api/v1/models/1/files --header 'Accept: application/json' --header 'Authorization: Bearer MY-BEARER-TOKEN' --form 'file[][email protected]' --form 'file[][email protected]' --form 'file[][email protected]' --form 'notes=Test' | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11794    0   820  100 10974   3253  43547 --:--:-- --:--:-- --:--:-- 46801
{
  "status": "success",
  "messages": "File(s) successfully uploaded.",
  "payload": {
    "total": 2,
    "rows": [
      {
        "id": 469,
        "icon": "far fa-file",
        "filename": "models-1-lAkpKihw-README.md",
        "inline": false,
        "filetype": null,
        "url": "https://snipe-it.test/models/1/showfile/469",
        "created_by": {
          "id": 1,
          "name": "Admin User"
        },
        "note": "Test",
        "created_at": {
          "datetime": "2025-05-19 22:10:16",
          "formatted": "Mon May 19, 2025 10:10PM"
        },
        "deleted_at": null,
        "available_actions": {
          "delete": true
        }
      },
      {
        "id": 470,
        "icon": "fas fa-vector-square",
        "filename": "models-1-hYayF7VT-poc.svg",
        "inline": false,
        "filetype": null,
        "url": "https://snipe-it.test/models/1/showfile/470",
        "created_by": {
          "id": 1,
          "name": "Admin User"
        },
        "note": "Test",
        "created_at": {
          "datetime": "2025-05-19 22:10:16",
          "formatted": "Mon May 19, 2025 10:10PM"
        },
        "deleted_at": null,
        "available_actions": {
          "delete": true
        }
      }
    ]
  }
}

This still needs a little massaging, but should make our bulk actions API endpoints more consistent, and will make it much easier to add new uploaded file capabilities to other first-class objects moving forward.

Update: Much further along now. A few issues remain:

  • We don't have a way from within the Presenter to determine what kind of actionsFormatter to use, since it's not really aware of what the object is.
  • I'd also like to rework the file messages to be more generic
  • The delete confirmation says "Are you sure you wish to delete undefined" - I think this is related to the first issue.
  • I'm no longer seeing the failed attempts when the file fails validation. This was working before but I seem to have bonked it in my other changes.
  • There's probably a way to loop through the object types in a single Uploads controller test, so we don't have to create separate tests when the behavior should be the same for all object types.
  • I'm having a helluva time getting the delete route to work via the javascript. They're named stupid anyway, so I might just need to refactor that bit. :(
  • If we can get the partial validation to work, that will change the shape of the response (where we show what went through and what didn't.)

Fixes #9413

snipe added 25 commits May 11, 2025 16:04
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
Signed-off-by: snipe <[email protected]>
@snipe snipe marked this pull request as draft May 19, 2025 21:12
@snipe snipe changed the title WIP: Rework upload API and responses WIP: Rework upload API for bulk and bettter responses May 19, 2025
@snipe snipe changed the title WIP: Rework upload API for bulk and bettter responses WIP: Rework upload API for bulk and better responses May 19, 2025
@snipe snipe added this to the v8.1.6 milestone Jun 2, 2025
@snipe snipe added the api label Jun 2, 2025
@snipe snipe moved this to In progress in Snipe-IT Awaiting Epic Jun 2, 2025
@snipe snipe changed the title WIP: Rework upload API for bulk and better responses WIP: Fixed #9413 and rework upload API for bulk and better responses Jun 2, 2025
@snipe snipe linked an issue Jun 2, 2025 that may be closed by this pull request
@snipe snipe linked an issue Jun 3, 2025 that may be closed by this pull request
@snipe snipe self-assigned this Jun 9, 2025
snipe added a commit that referenced this pull request Jun 27, 2025
 Fixed #9413 and rework upload API for bulk and better responses (refactor of #16964)
@snipe
Copy link
Member Author

snipe commented Jun 27, 2025

Closing this as I'm refactoring it down to smaller chunks

@snipe snipe closed this Jun 27, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in Snipe-IT Awaiting Epic Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Importing asset file through API FEATURE REQUEST: File Upload via REST API

2 participants