小编Aka*_*han的帖子

如何使用nodejs将内存文件数据上传到谷歌云存储?

我正在从网址读取图像并进行处理.我需要将此数据上传到云存储中的文件,目前我正在将数据写入文件并上传此文件然后删除此文件.有没有办法可以将数据直接上传到云存储?

static async uploadDataToCloudStorage(rc : RunContextServer, bucket : string, path : string, data : any, mimeVal : string | false) : Promise<string> {
if(!mimeVal) return ''

const extension = mime.extension(mimeVal),
      filename  = await this.getFileName(rc, bucket, extension, path),
      modPath   = (path) ? (path + '/') : '',
      res       = await fs.writeFileSync(`/tmp/${filename}.${extension}`, data, 'binary'),
      fileUrl   = await this.upload(rc, bucket, 
                            `/tmp/${filename}.${extension}`,
                            `${modPath}${filename}.${extension}`)

await fs.unlinkSync(`/tmp/${filename}.${extension}`)

return fileUrl
}

static async upload(rc : RunContextServer, bucketName: string, filePath : string, destination : string) : Promise<string> { …
Run Code Online (Sandbox Code Playgroud)

node.js google-cloud-storage

8
推荐指数
2
解决办法
3333
查看次数

如何从谷歌数据存储中祖先查询的返回对象中检索完整键?

我正在使用祖先查询使用 nodejs 从谷歌数据存储中检索实体

query = datastore.createQuery(entity).hasAncestor(key)

关键在哪里

key = datastore.key([kind_name_of_parent, id_of_parent])

我能够检索对象,但我想获取检索对象的完整键,而返回的数组仅包含返回的对象和 endCursor。

我怎样才能得到完整的密钥?或者,我可以从 endCursor 获得完整的密钥吗?

我的查询结果的一个例子是:

[{ modTS: 1481006473081, modLoc: null, modUid: 0, createTS: 1481006473081 } ], { moreResults: 'NO_MORE_RESULTS', endCursor: 'CloSVGoTc350ZXN0cHJvamVjdC0zN2ZiNnI9CxIEdXNlchiAgID409OICgw??LEgRzaW1zGICAgICAgIA??KDAsSDmNsaWVudFNldHR??wsdrfGICAgICA5NEKDBg??AIAA=' } ]

google-app-engine node.js google-cloud-datastore

5
推荐指数
1
解决办法
889
查看次数

npm 命令不显示任何输出或结果

npm -v 没有给出任何输出

请参阅附图。我已经安装了node.js。打开我的 git bash 后,如果我运行 node -v,它会给我节点版本,但是在我写 npm -v 后,我已经过了很长一段时间,比如 30 多分钟。它给了我任何输出。没有错误或警告,什么也没有。就像我所附的图片一样。这也是命令-

shamim@DESKTOP-3C7P5TO MINGW64 /e/wamp64/www/vuejspractice/vue-cli-dev
$ node -v
v8.9.4

shamim@DESKTOP-3C7P5TO MINGW64 /e/wamp64/www/vuejspractice/vue-cli-dev
$ npm -v
Run Code Online (Sandbox Code Playgroud)

当我运行这个时也得到同样的结果

npm install
Run Code Online (Sandbox Code Playgroud)

经过30多分钟的漫长时间才过去。什么都没发生。

请有人给我一个解决方案。

javascript node.js npm npm-install

5
推荐指数
1
解决办法
6490
查看次数

Typescript 版本与 Node 版本

由于Typescript是一个全局的npm模块,那么Typescript版本和Node版本之间有什么关系吗?

即,我是否需要运行任何特定版本的打字稿所需的最低节点版本。

node.js npm typescript

2
推荐指数
1
解决办法
9699
查看次数

Javascript,在promise中调用函数

代码说明

我有一个函数调用placeDecode,它接受一个HTML输入元素.在函数中,我有一个将输入值转换为格式化地址的promise.

我打了placeDecode两次电话,检查两个调用时是否已经解析我使用Promise.all,检查每个函数调用.当我尝试调用函数时出现问题viewResult,我得到Cannot read property 'viewresult' of undefined错误.


  //call function twice
    var startAddress = this.placeDecode1(this.searches.startSearch);
    var endAddress = this.placeDecode1(this.searches.endSearch);
  
    //promise all
    Promise.all([endAddress,startAddress]).then(function(values) {
      this.viewResult(values);

    }).catch(function(result){
      console.log(result);
    })

    console.log('hit');
  }


  //method convertes input into formatted address
  private placeDecode1(input: HTMLInputElement) {

    var result = new Promise(function(resolve, reject) {
      var location = input.value;

      var geoCode = new google.maps.Geocoder();
      geoCode.geocode({
        address: location
      }, function(result,status){
        if(status == 'OK'){
          console.log(result[0].formatted_address);
          resolve(result[0].formatted_address);
        }
      })
    });

    return result;

  } …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous promise typescript

0
推荐指数
1
解决办法
1132
查看次数

Visual Studio Code 中的 var_dump 快捷方式访问

如何在 Visual Studio Code 编辑器中快速访问 var_dump?例如:我输入vd字母,按 Enter 键后我得到var_dump("");.

php var-dump visual-studio-code

0
推荐指数
1
解决办法
1830
查看次数