Renamed REST param to "chunk"
Also, call node.store without blockSize param if "?chunk" isn't specified in the upload URL
This commit is contained in:
parent
452e344bf3
commit
0fcdaff937
|
@ -161,10 +161,10 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
|
||||||
router.rawApi(
|
router.rawApi(
|
||||||
MethodPost,
|
MethodPost,
|
||||||
"/api/codex/v1/upload") do (
|
"/api/codex/v1/upload") do (
|
||||||
blockSize: Option[uint]
|
chunk: Option[uint]
|
||||||
) -> RestApiResponse:
|
) -> RestApiResponse:
|
||||||
## Upload a file in a streamming manner,
|
## Upload a file in a streamming manner,
|
||||||
## split it into blocks of blockSize,
|
## split it into blocks of `chunk` bytes,
|
||||||
## and save to the node's BlockStore
|
## and save to the node's BlockStore
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@ -177,12 +177,16 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
|
||||||
# wait 1000ms before giving up
|
# wait 1000ms before giving up
|
||||||
await request.handleExpect()
|
await request.handleExpect()
|
||||||
|
|
||||||
let
|
let bodyStream = AsyncStreamWrapper.new(reader = AsyncStreamReader(bodyReader.get))
|
||||||
bodyStream = AsyncStreamWrapper.new(reader = AsyncStreamReader(bodyReader.get))
|
|
||||||
blockSize = (blockSize.get |? BlockSize).int
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
without cid =? (await node.store(bodyStream, blockSize)), error:
|
let runUpload =
|
||||||
|
if blockSize =? chunk.get:
|
||||||
|
node.store(bodyStream, blockSize = blockSize.int)
|
||||||
|
else:
|
||||||
|
node.store(bodyStream)
|
||||||
|
|
||||||
|
without cid =? (await runUpload), error:
|
||||||
trace "Error uploading file", exc = error.msg
|
trace "Error uploading file", exc = error.msg
|
||||||
return RestApiResponse.error(Http500, error.msg)
|
return RestApiResponse.error(Http500, error.msg)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue