// 云函数入口文件
const cloud = require('wx-server-sdk')
var request = require('request-promise');
// const fs = require('fs');
cloud.init({
  env: 'productapp-hsk0o'
})

// 云函数入口函数
exports.main = async (event, context) => {
  // var fileStr=fs.createReadStream(event.filePath)
  var formData = {
    // file : fs.createReadStream(event.filePath)
    // fileBase64 : '22'
    fileBase64:event.fileBase64
	}
  return await new Promise((resolve, reject) => {
    // var namenn= JSON.stringify(formData);
    
    request({
      url: event.url,
      method: "POST",
      json: true,
      body:event.fileBase64,
      headers: {
        "content-type": "application/json",
        // "content-Type": "application/x-www-form-urlencoded",
        // 'User-Agent': 'Request-Promise'
        // "token": event.token
      },
    }, function (error, response, body) {
      console.log("响应" + body)
      resolve(body)
      if (!error && response.statusCode == 200) {
        try {

        } catch (e) {
          reject()
        }
      }
    })
  })
}