【发布时间】:2019-02-19 11:55:06
【问题描述】:
我正在尝试以编程方式将 .apk / .ipa 文件上传到 browserstack 云(而不是运行 curl 命令)
选项 1:节点获取 api
const myfetch = require('node-fetch');
const buildToPost = {
file: '</my path>'
};
const options = {
method: 'POST',
body: JSON.stringify(buildToPost)
};
myfetch('https://</myusername>:</mykey>@api.browserstack.com/app-automate/upload', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(error => console.error('Error:', error));
但它给出以下错误:
{ 错误:'格式无效。有关有效 API,请参阅 REST API 文档 格式 - https://www.browserstack.com/app-automate/rest-api' }
选项 2:Axios API
const axios = require('axios');
axios.post('https://</myusername>:</mykey>@api-cloud.browserstack.com/app-automate/upload', {
File: '</my path>'
})
.then
((response) => {
console.log(response);
}).catch((error) => {
console.log((error));
})
错误:数据:
{ 错误: '无效的格式。有关有效的 API 格式,请参阅 REST API 文档 - https://www.browserstack.com/app-automate/rest-api' } } }
卷曲命令参考:
curl -u "</myusername>:</mykey>" -X POST https://api-cloud.browserstack.com/app-automate/upload -F "file=@/path/to/app/file/Application-debug.apk" -F 'data={"custom_id": "MyApp"}'
【问题讨论】:
-
注意:要上传的文件存在于本地磁盘/文件夹中
标签: axios fetch webdriver-io browserstack