我們正在嘗試將文件上傳到Google Cloud Storage中,然後將它們移到BigQuery中,但我們經常遇到'500 Internal Server Error'或'410 Gone'(下面的原始消息)在一些上傳過程中。將文件上傳到Google雲端存儲:500後端錯誤
我們使用官方的SDK,並添加了指數退避的重試,但錯誤總是在這裏。你有任何建議嗎?
下面是我們如何上傳(斯卡拉):
val credential = new GoogleCredential().setAccessToken(accessToken)
val requestInitializer = new HttpRequestInitializer() {
def initialize(request: HttpRequest): Unit = {
credential.initialize(request)
// to avoid read timed out exception
request.setConnectTimeout(200000)
request.setReadTimeout(200000)
request.setIOExceptionHandler(new
HttpBackOffIOExceptionHandler(new ExponentialBackOff()))
request.setUnsuccessfulResponseHandler(new
HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()))
}
}
val storage = new Storage.Builder(
new NetHttpTransport,
JacksonFactory.getDefaultInstance,
requestInitializer
).setApplicationName("MyAppHere").build
val objectMetadata = new StorageObject()
.setBucket(bucketName)
.setName(distantFileName)
val isc = new InputStreamContent("binary/octet-stream", fis)
val length = isc.getLength
val insertObject = storage.objects().insert(bucketName, objectMetadata, isc)
// For small files, you may wish to call setDirectUploadEnabled(true), to
// reduce the number of HTTP requests made to the server.
if (length > 0 && length <= 2 * 1000 * 1000 /* 2MB */) {
insertObject.getMediaHttpUploader.setDirectUploadEnabled(true)
}
insertObject.execute()
我們的斯卡拉依賴關係:
"com.google.api-client" % "google-api-client" % "1.18.0-rc",
"com.google.api-client" % "google-api-client-jackson2" % "1.18.0-rc",
"com.google.apis" % "google-api-services-bigquery" % "v2-rev142-1.18.0-rc",
"com.google.apis" % "google-api-services-storage" % "v1-rev1-1.18.0-rc",
"com.google.http-client" % "google-http-client" % "1.18.0-rc",
"com.google.oauth-client" % "google-oauth-client" % "1.18.0-rc"
生SDK的錯誤響應:
500 Internal Server Error
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Backend Error",
"reason" : "backendError"
} ],
"message" : "Backend Error"
}
410 Gone
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Backend Error",
"reason" : "backendError"
} ],
"message" : "Backend Error"
}
感謝您發表評論 – mecanix
得到410作爲對上述代碼的迴應,特別是當結果中包含「代碼」:「500」時,這是非常令人驚訝的。你有可能修改你的結果的某種防火牆嗎? –
@BrandonYarbrough我們的防火牆不會修改任何內容,它只是過濾互聯網流量 – mecanix