我正在使用react-native-image-crop-picker来显示图像,我可以使用相同的代码显示和上传由同一插件从画廊拍摄的图像。...而我可以使用相同的图像显示从相机拍摄的图像插件...但是无法将其上传到服务器。
我得到的错误是
buildscript {
repositories {
google()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.26.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'devicefarm'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 27
defaultConfig {
applicationId 'expo.reactnative.test'
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName '1.0.0'
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Deprecated. Used by net.openid:appauth
manifestPlaceholders = [
'appAuthRedirectScheme': 'host.exp.exponent'
]
}
dexOptions {
javaMaxHeapSize System.getenv("DISABLE_DEX_MAX_HEAP") ? null : "8g"
}
flavorDimensions 'remoteKernel'
productFlavors {
devKernel {
dimension 'remoteKernel'
}
prodKernel {
dimension 'remoteKernel'
}
}
signingConfigs {
debug {
storeFile file('../debug.keystore')
}
release {
storeFile file(System.getenv("ANDROID_KEYSTORE_PATH") ?: "release-key.jks")
storePassword System.getenv("ANDROID_KEYSTORE_PASSWORD")
keyAlias System.getenv("ANDROID_KEY_ALIAS")
keyPassword System.getenv("ANDROID_KEY_PASSWORD")
}
}
buildTypes {
debug {
debuggable true
ext.enableCrashlytics = false
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
lintOptions {
abortOnError false
}
packagingOptions {
pickFirst "**"
}
configurations.all {
resolutionStrategy.force 'com.android.support:design:27.1.0'
}
}
devicefarm {
projectName System.getenv("DEVICEFARM_PROJECT_NAME")
devicePool System.getenv("DEVICEFARM_DEVICE_POOL")
executionTimeoutMinutes 40
authentication {
accessKey System.getenv("AWS_ACCESS_KEY_ID")
secretKey System.getenv("AWS_SECRET_ACCESS_KEY")
}
}
configurations.all {
resolutionStrategy {
force 'org.webkit:android-jsc:r224109'
}
}
// WHEN_PREPARING_SHELL_REMOVE_FROM_HERE
apply from: 'expo.gradle'
// WHEN_PREPARING_SHELL_REMOVE_TO_HERE
dependencies {
implementation project(':react-native-firebase')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-analytics:16.5.0'
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:16.1.0"
//
implementation 'com.android.support:multidex:1.0.1'
// Our dependencies
implementation 'com.android.support:appcompat-v7:27.1.1'
// Our dependencies from ExpoView
// DON'T ADD ANYTHING HERE THAT ISN'T IN EXPOVIEW. ONLY COPY THINGS FROM EXPOVIEW TO HERE.
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.facebook.android:facebook-android-sdk:4.37.0'
implementation('com.facebook.android:audience-network-sdk:4.99.0') {
exclude module: 'play-services-ads'
}
compileOnly 'org.glassfish:javax.annotation:3.1.1'
implementation 'com.jakewharton:butterknife:8.4.0'
implementation 'de.greenrobot:eventbus:2.4.0'
// Be careful when upgrading! Upgrading might break experience scoping. Check with Jesse. See Analytics.resetAmplitudeDatabaseHelper
implementation 'com.amplitude:android-sdk:2.9.2'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-ads:17.2.0'
annotationProcessor 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
implementation "com.raizlabs.android:DBFlow-Core:2.2.1"
implementation "com.raizlabs.android:DBFlow:2.2.1"
implementation "com.madgag.spongycastle:core:1.53.0.0"
implementation "com.madgag.spongycastle:prov:1.53.0.0"
debugImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
implementation 'com.facebook.device.yearclass:yearclass:2.1.0'
implementation 'commons-io:commons-io:1.4'
implementation 'me.leolin:ShortcutBadger:1.1.4@aar'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.yqritc:android-scalablevideoview:1.0.1'
implementation 'commons-codec:commons-codec:1.10'
implementation 'com.segment.analytics.android:analytics:4.3.0'
implementation 'com.google.zxing:core:3.3.3'
implementation 'net.openid:appauth:0.4.1'
implementation('com.airbnb.android:lottie:2.5.5') {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
implementation('io.nlopez.smartlocation:library:3.2.11') {
transitive = false
}
implementation 'com.android.support:exifinterface:27.1.1'
implementation 'com.squareup.okio:okio:1.9.0'
implementation 'com.facebook.soloader:soloader:0.5.1'
implementation 'com.google.android.exoplayer:exoplayer:2.6.1'
implementation 'expolib_v1.com.google.android.exoplayer:expolib_v1-extension-okhttp:2.6.1@aar'
// expo-file-system
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.10.0'
// Testing
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// We use a modified build of com.android.support.test:runner:1.0.1. Explanation in maven-test/README
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.0'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'org.robolectric:robolectric:3.8'
testImplementation 'com.android.support.test:runner:1.0.2-alpha1'
testImplementation 'com.android.support.test:rules:1.0.2-alpha1'
implementation('host.exp.exponent:expoview:32.0.0@aar') {
transitive = true
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
exclude group: 'com.squareup.okhttp3', module: 'okhttp-urlconnection'
}
api 'com.facebook.react:react-native:32.0.0'
api 'host.exp.exponent:expo-app-loader-provider:1.0.0'
api 'host.exp.exponent:expo-core:2.0.0'
api 'host.exp.exponent:expo-constants-interface:2.0.0'
api 'host.exp.exponent:expo-constants:2.0.1'
api 'host.exp.exponent:expo-errors:1.0.0'
api 'host.exp.exponent:expo-file-system-interface:2.0.0'
api 'host.exp.exponent:expo-file-system:2.0.0'
api 'host.exp.exponent:expo-image-loader-interface:2.0.0'
api 'host.exp.exponent:expo-permissions:2.0.0'
api 'host.exp.exponent:expo-permissions-interface:2.0.0'
api 'host.exp.exponent:expo-sensors-interface:2.0.0'
api 'host.exp.exponent:expo-react-native-adapter:2.0.0'
api 'host.exp.exponent:expo-task-manager:1.0.0'
api 'host.exp.exponent:expo-task-manager-interface:1.0.0'
// Optional universal modules, could be removed
// along with references in MainActivity
api 'host.exp.exponent:expo-ads-admob:2.0.0'
api 'host.exp.exponent:expo-app-auth:2.0.0'
api 'host.exp.exponent:expo-analytics-segment:2.0.0'
api 'host.exp.exponent:expo-barcode-scanner-interface:2.0.0'
api 'host.exp.exponent:expo-barcode-scanner:2.0.0'
api 'host.exp.exponent:expo-camera-interface:2.0.0'
api 'host.exp.exponent:expo-camera:2.0.0'
api 'host.exp.exponent:expo-contacts:2.0.0'
api 'host.exp.exponent:expo-face-detector:2.0.0'
api 'host.exp.exponent:expo-face-detector-interface:2.0.0'
api 'host.exp.exponent:expo-font:2.0.0'
api 'host.exp.exponent:expo-gl-cpp:2.0.0'
api 'host.exp.exponent:expo-gl:2.0.0'
api 'host.exp.exponent:expo-google-sign-in:2.0.0'
api 'host.exp.exponent:expo-local-authentication:2.0.0'
api 'host.exp.exponent:expo-localization:2.0.0'
api 'host.exp.exponent:expo-location:2.0.1'
api 'host.exp.exponent:expo-media-library:2.0.0'
api 'host.exp.exponent:expo-print:2.0.0'
api 'host.exp.exponent:expo-sensors:2.0.0'
api 'host.exp.exponent:expo-sms:2.0.0'
api 'host.exp.exponent:expo-background-fetch:1.0.0'
}
// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'
}
// This has to be down here for some reason
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
我的图像信息是:
Error: Request failed with status code 500
at createError (C:\Repos\247client\node_modules\axios\lib\core\createError.js:16)
at settle (C:\Repos\247client\node_modules\axios\lib\core\settle.js:18)
at XMLHttpRequest.handleLoad (C:\Repos\247client\node_modules\axios\lib\adapters\xhr.js:77)
at XMLHttpRequest.dispatchEvent (C:\Repos\247client\node_modules\event-target-shim\lib\event-target.js:172)
at XMLHttpRequest.setReadyState (C:\Repos\247client\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:572)
at XMLHttpRequest.__didCompleteResponse (C:\Repos\247client\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:394)
at C:\Repos\247client\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:507
at RCTDeviceEventEmitter.emit (C:\Repos\247client\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190)
at MessageQueue.__callFunction (C:\Repos\247client\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:349)
at C:\Repos\247client\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:106
我同时使用相同的上传代码,即上传从图库和相机拍摄的图像。
代码是
{uri: "file:///storage/emulated/0/Pictures/b9e9acdd-5807-43c8-9c6b-08af4f9e37ce.jpg", width: 3456, height: 4608, mime: "image/jpeg", size: 247313}
height: 4608
mime: "image/jpeg"
size: 247313
uri: "file:///storage/emulated/0/Pictures/b9e9acdd-5807-43c8-9c6b-08af4f9e37ce.jpg"
width: 3456
答案 0 :(得分:0)
请参阅https://stackoverflow.com/a/62087375/6508545
中给出的答案我曾经使用过react-native-image-crop-picker npm软件包来从Camera Roll和Photo Gallery获取图像。然后将其上传到 AWS S3服务器。
我可以轻松地从IOS设备上传它,但不能从Android上传。
问题是在android和IOS设备中获取的图像的URI或文件路径不同。
示例文件路径变量数据
” /用户/ Niveditha / Library / Developer / CoreSimulator / Devices / B41EB910-F22B-4236-8286-E6BA3EA75C70 / data / Containers / Data / Application / B88777C6-6B10-4095-AB67-BB11E045C1DE / tmp / react-native-image-crop-picker / img.jpg“
“ 文件:// /storage/emulated/0/Android/data/com.uploadcameraroll/files/Pictures/img.jpg”