在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/網(wǎng)絡(luò)安全/ vertx如何接收-data-binary形式上傳的文件

vertx如何接收-data-binary形式上傳的文件

使用如下的方式上傳文件給某個(gè)服務(wù):
curl -H 'X-SWR-Override:1' https://ip:port/repo/v2/file_paths/kafka.tar.gz --data-binary @kafka.tar.gz -X PUT

服務(wù)端用vertx應(yīng)該如何實(shí)現(xiàn)?

下面是搜了資料說(shuō)可以多次調(diào)用下面的語(yǔ)句,但是具體怎么實(shí)現(xiàn)呢?

這是因?yàn)閎ody可能會(huì)非常大 (例如一個(gè)文件上傳),我們通常不不會(huì)吧緩沖的整個(gè)body放在內(nèi)
存中交給你,因?yàn)槟菍?dǎo)致服務(wù)器內(nèi)存用盡。
若要接收body,您可以使用handler請(qǐng)求,調(diào)用后,會(huì)有請(qǐng)求body到達(dá)。

request.handler(buffer -> {
System.out.println("I have received a chunk of the body of length " + buffer.length(
));
});
傳遞到handler的對(duì)象是一個(gè)Buffer,該handler可以調(diào)用多次,當(dāng)數(shù)據(jù)到達(dá)時(shí)從網(wǎng)絡(luò),根據(jù)
body的大小。

回答
編輯回答
胭脂淚

Handling file uploads
Body handler is also used to handle multi-part file uploads.

If a body handler is on a matching route for the request, any file uploads will be automatically streamed to the uploads directory, which is file-uploads by default.

Each file will be given an automatically generated file name, and the file uploads will be available on the routing context with fileUploads.

Here’s an example:

router.route().handler(BodyHandler.create());

router.post("/some/path/uploads").handler(routingContext -> {

Set<FileUpload> uploads = routingContext.fileUploads();
// Do something with uploads....

});
Each file upload is described by a FileUpload instance, which allows various properties such as the name, file-name and size to be accessed.

2018年5月11日 02:56