因此,当我请求我的网络服务下载 zip 文件时,它会秘密下载文件内容,突然间,该文件出现在下载任务栏中,但已下载完整(100%)
使用以下角度方法:
const endpoint = "http://localhost:8080/download/zip"
this.http.get<Blop>(endpoint, {headers: httpHeaders, responseType: 'blob', reportProgress: true })
Run Code Online (Sandbox Code Playgroud)
这就是我的订阅方式:
this.http.get<Blop>(endpoint, {headers: httpHeaders, responseType: 'blob', reportProgress: true }).subscribe({
next: data => {
console.log('blocking or not');
const blob = new Blob([data as any], { type: 'application/zip' });
window.location.href = URL.createObjectURL(blob);
}
})
Run Code Online (Sandbox Code Playgroud)
所以我注意到 myconsole.log(...)直到下载结束才被调用,所以我认为浏览器用户界面无法检测到下载,直到它到达window.location.href.
如何强制传输结束前将下载显示在下载任务栏中,并在浏览器中查看下载进度?我找不到任何与异步 blop 或类似内容相关的内容。
PS:我的后端正在提供数据流,所以后端不是问题。当通过浏览器直接调用我的api时,我们可以在下载任务栏中看到下载进度。不过,如果你们感兴趣,这是片段(spring-boot)
@GetMapping("/download/zip")
fun download(response: HttpServletResponse): StreamingResponseBody {
val file = downloads.download("launcher")
response.contentType = "application/zip"
response.setHeader(
"Content-Disposition",
"attachment;filename=sample.zip"
)
response.setContentLengthLong(file.length())
return StreamingResponseBody { outputStream: …Run Code Online (Sandbox Code Playgroud) 我的数组看起来像这样:
[sx1] => Array
(
[sx1] => Pain in Hand
[sx1L] => Location
[sx1O] => Other Treat
[sx1T] => Type
[sx1R] => Radiation
[sx1A] => Aggrivate Ease
[sx1D] => Duration
[sx1I] => Irit
[sx1P] => Previous Hx
[SX1T_1] => CX
[SX1T_2] => Shld
[SX1T_3] => Trnk
[SX1T_4] => Hip
[SX1T_5] =>
)
Run Code Online (Sandbox Code Playgroud)
我需要能够通过键搜索数组,然后返回匹配项的索引.例如,我需要在数组中搜索键"SX1T_1",然后返回数组中该项的索引.
谢谢你的帮助.
调试 lambda 令人沮丧。
我有一个非常简单的 lambda 函数:
const AWS = require('aws-sdk')
const dynamodb = new AWS.DynamoDB.DocumentClient({region: 'ap-southeast-2'});
exports.handler = async (event, context, callback) => {
const params = {
TableName: 'people-dev',
Item: {
id: '1',
name: 'person',
email: 'person@example.com'
}
};
dynamodb.put(params, (err, data) => {
if(err) {
callback(err, null)
} else{
callback(null, data)
}
});
};
Run Code Online (Sandbox Code Playgroud)
测试响应是:
Response:
null
Request ID:
"3d7e9329-3843-4760-917d-4b4d4781dbd7"
Function Logs:
START RequestId: 3d7e9329-3843-4760-917d-4b4d4781dbd7 Version: $LATEST
END RequestId: 3d7e9329-3843-4760-917d-4b4d4781dbd7
REPORT RequestId: 3d7e9329-3843-4760-917d-4b4d4781dbd7 Duration: 243.13 ms Billed Duration: …Run Code Online (Sandbox Code Playgroud) 这是我的代码
$string = preg_replace("/rad\:([0-9]+)px\;\s+\/\*\sALT\[(.+)\*\/|rad\:([0-9]+)px\;/",("$2"?"$2":"$1"),$string);
Run Code Online (Sandbox Code Playgroud)
基本上,在正则表达式中我有一个管道 |,并且我正在搜索两种模式。如果与第一个模式(管道左侧)匹配,那么我希望将其替换为第二个捕获组($2),但如果它与第二个模式匹配(管道右侧)管道),然后我希望将其替换为第一个捕获组($1);
我尝试过的代码不起作用。这有可能吗?
谢谢你的帮助。
php ×2
angular ×1
arrays ×1
aws-lambda ×1
blob ×1
javascript ×1
preg-match ×1
regex ×1
stream ×1
typescript ×1