使用Blobstore API进行GAE下载无法正常工作,错误消息-无法加载资源:服务器响应状态为500()

时间:2018-11-09 17:12:18

标签: google-app-engine google-cloud-storage blobstore

GAE应用程序中的代码(使用Blobstore API下载文件)三天前在生产中停止工作。 用于下载文件的代码过去使用了很多年。

let counter = 1;
let data = [];
function AddDetails(){
  var button = document.getElementById('button');
  button.addEventListener('click', SaveDetails, false);
  let sortBy = document.getElementById('sortBy');
  sortBy.addEventListener('change', SortAndDisplay, false);
  document.getElementById('userID').value = counter;
}
function SortAndDisplay(){
  console.log("Sorting", document.getElementById('sortBy').value);
  let sortBy = document.getElementById('sortBy').value;
  if(sortBy === "userID"){
    data.sort(function (a, b) {
      return a.id - b.id;
    });
  }
  else{
    sortByNameOrOccupation(sortBy);
  }
  console.log(data);
  displayAfterSort();


}
function SaveDetails(){


  let name = document.getElementById('userName');
  let occupation = document.getElementById('userOccupation');
  data.push({id: counter, name: name.value, occupation: occupation.value });
  console.log(data);
  counter++;
  document.getElementById('userID').value = counter;
  name.value='';
  occupation.value ='';

  let outputSection  = document.getElementById('output');
  let outputData = data[data.length - 1];
  let newP = document.createElement('p');
  newP.textContent = outputData['id'] + " " + outputData['name'] + "  "+outputData['occupation'];
  outputSection.appendChild(newP);


}

function sortByNameOrOccupation(attribute){
  data.sort(function(a, b) {
    var nameA = a[attribute].toUpperCase(); // ignore upper and lowercase
    var nameB = b[attribute].toUpperCase(); // ignore upper and lowercase
    if (nameA < nameB) {
      return -1;
    }
    if (nameA > nameB) {
      return 1;
    }

    // names must be equal
    return 0;
  });
}

function displayAfterSort(){
  let outputSection  = document.getElementById('output');
  outputSection.innerHTML = '';
  let fragment = document.createDocumentFragment();
  data.forEach(function(d) {
      let p = document.createElement('p');
      p.textContent = d['id'] + " " + d['name'] + "  "+d['occupation'];
      fragment.appendChild(p);
  });
  outputSection.appendChild(fragment);

}


window.addEventListener('load', AddDetails, false);

此代码从最近3天开始给出错误“无法加载资源:服务器以500()状态响应”。

第二种方法 我们还尝试改用GCS API

String key = "AMIfv96IYjdE0eMB2m12zFW....";
BlobKey blobKey = new BlobKey(key);
blobstoreService.serve(blobKey, res);

使用此代码,我们会收到错误消息

  

错误了java.lang.RuntimeException:的 PrefetchingGcsInputChannelImpl [文件名= GcsFilename(rnlgpc-文档-入夹,案例/外壳-5710601580969984 / L2FwcGhvc3RpbmdfZ2xvYmFsL2Jsb2JzL0FFbkIyVXJ6djNmRnc4aFlNZHBvMmlqYW5fd2FNWVJ3R29aaGR3WVBXcmJLWk9RN1lDVUNnN1VLcTV6dFBTeWl2OWxWellyNVZPWTJ1dEdWZFVlYnhmSC12S2pkaEhxeFZzbFNIUzNrZndobEpZeGd1VjVoc0lBLlVZMi13QjJmaFZpYkZzWUw),blockSizeBytes = 2097152,闭合=假,eofHit =假,长度= -1,fetchPosition = 0,pendingFetch = com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsService $ 2 @ 370bdb99,retryParams = RetryParams [requestTimeoutMillis = 30000,requestTimeoutRetryFactor = 1.2,maxRequestTimeout = 60000,retryMinAttempts = 3, 10,initialRetryDelayMillis = 10,maxRetryDelayMillis = 32000,retryDelayBackoffFactor = 2.0,totalRetryPeriodMillis = 15000]]: ExecutionException的未知原因

第三种方法 然后,我们尝试使用Cloud Storage JSON API

Blob blob = storage.get(BlobId.of(bucketName, srcFilename));
GcsFilename fileName = new GcsFilename(blob.getBucket(), blob.getName());
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
copy(Channels.newInputStream(readChannel), res.getOutputStream());

使用此代码,我们可以下载具有'gsObjectName'可用的文件。

对于较旧的文件,我们只有Blob键。我们该如何下载这些文档,并且blobstore api(原始方法)又可以使用,因为它尚未被弃用?

谢谢!! 阿德哈尔(Aadhaar)

0 个答案:

没有答案