gpt4 book ai didi

javascript - 捕获音频并上传

转载 作者:行者123 更新时间:2023-11-29 15:42:14 24 4
gpt4 key购买 nike

我在移动设备 (iOS) 上工作。我使用 HTML/CSS/Javascript 开发混合应用程序。

我的代码建立在 Apache Cordova API 上:

<!DOCTYPE html>
<html>
<head>
<title>Capture Audio</title>

<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8" src="json2.js"></script>
<script type="text/javascript" charset="utf-8">

// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}

// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureAudio() {
// Launch device audio recording application,
// allowing user to capture up to 2 audio clips
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit: 2});
}

// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;

ft.upload(path,
"http://my.domain.com/upload.php",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}

</script>
</head>
<body>
<button onclick="captureAudio();">Capture Audio</button> <br>
</body>
</html>

我可以用它捕捉我的声音,理论上可以上传到

http://my.domain.com/upload.php

但我想知道如何调整此代码以在我的 Dropbox 上上传文件。上传文件到 Dropbox 有可能这么简单吗?

最佳答案

正如@sinaneker 提到的,您可以使用 PHP(或其他语言)在服务器端执行此操作。

但您也可以使用 Dropbox 的 JavaScript 库直接从 JavaScript 执行此操作:https://github.com/dropbox/dropbox-js

关于javascript - 捕获音频并上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17501828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com