WEB端直传媒体存储流程优化实践 URL 过期时间(单位:秒) 构建上传预签名 URL 的请求参数 params { 'Bucket': bucket, 'Key': key, 'ContentType': 'text/plain' 替换为你要上传的文件的 MIME 类型 } presignedurl s3client.generatepresignedurl( ClientMethod'putobject', Paramsparams, ExpiresInexpirationtime) print(f"presignedurl:{presignedurl}") if name 'main': AK 'xxx' SK 'xxx' bucketName 'hptest' objectKey 'postdog.png' endpoint ' region'apeast1' generateputobjectpresignedurl(AK,SK,endpoint,bucketName,objectKey,region) WEB端上传的时候,URL使用从应用服务器获取到的预签名URL: 使用 PUT 请求上传文件内容 使用 PUT 请求上传文件内容 上传文件 function uploadFile() { var fileInput document.getElementById('fileInput'); if (fileInput.files.length 0) { alert('请选择要上传的文件'); return; } var file fileInput.files[0]; var xhr new XMLHttpRequest(); xhr.open('PUT', '/xxxx', true); // 替换成实际的上传 URL //要上传的文件的 MIME 类型,需要与生成预签名的时候一致 xhr.setRequestHeader('ContentType', file.type); // 设置请求头的 ContentType xhr.onload function() { if (xhr.status 200) { alert('文件上传成功'); } else { alert('文件上传失败'); } }; xhr.send(file); }