gpt4 book ai didi

Cannot upload data to Dropbox with react-native-blob-util(无法使用REACT-Native-BLOB-Util将数据上载到Dropbox)

转载 作者:bug小助手 更新时间:2023-10-25 20:03:23 24 4
gpt4 key购买 nike



I am trying to upload a rather large file (~100mb, SQLite database) to Dropbox with react-native-blob-util. I authenticate with Dropbox to get an access token react-native-app-auth. The response I am getting from react-native-blob-util is that it worked: It goes into the then block. When I console.log() the res I get this (the data prop looks suspicious):

我正在尝试上传一个相当大的文件(~100MB,SQLite数据库)到Dropbox与反应-原生-斑点-util。我使用Dropbox进行身份验证,以获得访问令牌REACT-Native-app-auth。我从action-ative-blob-util得到的回应是它起作用了:它进入了THEN块。当我sole.log()Res时,我得到这样的结果(数据属性看起来可疑):


{"array": [Function anonymous], "base64": [Function anonymous], "blob": [Function anonymous], "data": "Error in call to API function \"files/upload\": Invalid authorization value in HTTP header \"Authorization\": \"sl.Bl...\".  Expecting \"Bearer <oauth2-access-token>\".", "flush": [Function anonymous], "info": [Function anonymous], "json": [Function anonymous], "path": [Function anonymous], "readFile": [Function anonymous], "readStream": [Function anonymous], "respInfo": {"headers": {"Accept-Encoding": "identity,gzip", "Cache-Control": "no-cache", "Connection": "close", "Content-Encoding": "gzip", "Content-Security-Policy": "sandbox allow-forms allow-scripts", "Content-Type": "text/plain; charset=utf-8", "Date": "Sun, 10 Sep 2023 08:21:22 GMT", "Server": "envoy", "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", "Transfer-Encoding": "Identity", "Vary": "Accept-Encoding", "X-Content-Type-Options": "nosniff", "X-Dropbox-Request-Id": "0d608050e40b41b79033ad96f82c1fac", "X-Dropbox-Response-Origin": "far_remote", "X-Robots-Tag": "noindex, nofollow, noimageindex"}, "redirects": ["https://content.dropboxapi.com/2/files/upload"], "respType": "text", "rnfbEncode": "utf8", "state": "2", "status": 400, "taskId": "...", "timeout": false}, "session": [Function anonymous], "taskId": "xxn9ye010qjh2yjcrl8u8", "text": [Function anonymous], "type": "utf8"}

Additionally, there is

此外,还有


a) nothing in my Dropbox (despite the App-Folder)
b) the upload takes about 1sec which is way too short for ~100mb.

A)我的Dropbox中什么都没有(尽管有App文件夹)b)上传大约需要1秒,对于~100MB来说太短了。


Here is the code.

以下是代码。


  const _authenticateDropbox = async () => {
const config = {
clientId: '...',
clientSecret: '...',
redirectUrl: 'org.reactjs.native.example..../oauth',
scopes: [],
serviceConfiguration: {
authorizationEndpoint: 'https://www.dropbox.com/oauth2/authorize',
tokenEndpoint: `https://www.dropbox.com/oauth2/token`,
},
additionalParameters: {
token_access_type: 'offline',
},
};
try {
const user = await authorize(config);
if (user) {
if (user.accessToken) _uploadData(user.accessToken);
}
} catch (error) {
console.warn('Something went wrong logging in into Dropbox, ', error);
}
};

const _uploadData = accessToken => {
const dbName = `${DATABASE_NAME}.db`;
const databasePath = `${RNFS.DocumentDirectoryPath}/${dbName}`;

ReactNativeBlobUtil.fetch(
'POST',
'https://content.dropboxapi.com/2/files/upload',
{
Authorization: accessToken,
'Dropbox-API-Arg': JSON.stringify({
path: '/foo.db',
mode: 'add',
autorename: true,
mute: false,
}),
'Content-Type': 'application/octet-stream',
},
ReactNativeBlobUtil.wrap(databasePath),
)
.uploadProgress({interval: 250}, (written, total) => {
...
})
.then(res => {
console.log(res)
console.log(accessToken) // its not empty, a looong string starting with sl.BlwH...
})
.catch(error => {
console.warn(error) // not logging
});
};

If I do a

如果我做一个


const databaseExists = await RNFS.exists(databasePath);
console.log(databaseExists); // true

it logs true, so the path is correct.
When I check the size of the file (just to make sure that this is no empty file) with

它记录为真,因此路径是正确的。当我使用以下命令检查文件大小时(只是为了确保这不是空文件)


ReactNativeBlobUtil.fs
.stat(databasePath)
.then(stats => {
console.log(stats);
})
.catch(err => {
console.warn(err);
});

It returns

它又回来了


{"filename": "foo.db", "lastModified": 1694194258000, "path": "/Users/.../Library/Developer/CoreSimulator/Devices/3B433335-5FEA-4324-BCD4-4CBB677C5A4E/data/Containers/Data/Application/98544ECA-3FDF-4D24-AEB8-F1015E2BEEAD/Documents/foo.db", "size": 108924928, "type": "file"}


So the file exists and has a size.

因此,该文件存在并且具有大小。


What am I missing?

我遗漏了什么?


Versions:

版本:


"react-native": "0.71.7",
"react-native-blob-util": "^0.19.1"
"react-native-app-auth": "^7.0.0",

更多回答
优秀答案推荐

The Authorization header should look like this

Authorization头应该如下所示


Authorization: `Bearer ${accessToken}`,

更多回答

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