[PR #75] [MERGED] Add streamed file upload #206

Closed
opened 2026-02-28 00:41:07 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Telmate/proxmox-api-go/pull/75
Author: @jmreyes
Created: 4/13/2020
Status: Merged
Merged: 5/28/2020
Merged by: @ggongaware

Base: masterHead: streaming-upload


📝 Commits (1)

📊 Changes

1 file changed (+59 additions, -1 deletions)

View changed files

📝 proxmox/client.go (+59 -1)

📄 Description

When uploading files, this library copies first the whole file in memory in order to build the POST body for the upload request.

Problem: large files may cause issues like the API consumer running out of memory. I have noticed this, for instance, when trying to upload some Windows ISOs using the Proxmox builder for Packer.

Solution in this PR: when possible, use MultiReader to stream the file directly from the reader into the request, without previously storing it in memory. In order to do so, the ContentLength header needs to be manually calculated and specified. To avoid breaking the API, this is only performed in case the Reader passed as the argument to Upload is a File: this way the file size can be obtained from the OS.

Of course, this PR open to any suggestions.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Telmate/proxmox-api-go/pull/75 **Author:** [@jmreyes](https://github.com/jmreyes) **Created:** 4/13/2020 **Status:** ✅ Merged **Merged:** 5/28/2020 **Merged by:** [@ggongaware](https://github.com/ggongaware) **Base:** `master` ← **Head:** `streaming-upload` --- ### 📝 Commits (1) - [`7ed1017`](https://github.com/Telmate/proxmox-api-go/commit/7ed10172eec462721ff0316181682f2ca125d1fd) Add streamed file upload ### 📊 Changes **1 file changed** (+59 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `proxmox/client.go` (+59 -1) </details> ### 📄 Description When uploading files, this library [copies](https://github.com/Telmate/proxmox-api-go/blob/a29566462efdea29d6b98618c11fa92caf1c46bd/proxmox/client.go#L770) first the whole file in memory in order to build the POST body for the upload request. Problem: large files may cause issues like the API consumer running out of memory. I have noticed this, for instance, when trying to upload some Windows ISOs using the Proxmox builder for Packer. Solution in this PR: when possible, use MultiReader to stream the file directly from the reader into the request, without previously storing it in memory. In order to do so, the ContentLength header needs to be manually calculated and specified. To avoid breaking the API, this is only performed in case the Reader passed as the argument to [Upload](https://github.com/Telmate/proxmox-api-go/blob/a29566462efdea29d6b98618c11fa92caf1c46bd/proxmox/client.go#L724) is a File: this way the file size can be obtained from the OS. Of course, this PR open to any suggestions. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:41:07 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmox-api-go#206
No description provided.