Skip to content

Commit

Permalink
fix(cli): Prevent transferKey::storeKey from hanging due to unknown b…
Browse files Browse the repository at this point in the history
…yte length
  • Loading branch information
nellh committed Nov 21, 2023
1 parent 35aab54 commit 007c955
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/openneuro-cli/src/transferKey.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stat } from "fs/promises"
import { createReadStream, createWriteStream } from "fs"
import { once } from "events"
import fetch, { Request } from "node-fetch"
Expand Down Expand Up @@ -32,9 +33,13 @@ export function keyRequest(state, key, options) {
* @param {string} file File path
*/
export async function storeKey(state, key, file) {
const fileStat = await stat(file)
const body = createReadStream(file)
const requestOptions = {
method: "POST",
headers: {
"Content-Length": fileStat.size,
},
}
const request = keyRequest(state, key, requestOptions)
const response = await fetch(request, { body })
Expand Down

0 comments on commit 007c955

Please sign in to comment.