'No getting response from Flask api hosted in GAE with Vue.js
I've been struggling to get the response from Flask api(hosted in GAE) with Vue.js. My response.data shows undefined in chrome console and when I tried to access this api in my localhost, I could get the correct response(uploaded Image URL). And I've already used CORS things in my api and looks no CORS error in console. Is there any way to check more detail error or anybody have an idea about this kind of problem?? Thank you so much !

uploadFile1: function () {
var img_file1 = this.$refs.img1.files[0]
this.imgFile1 = URL.createObjectURL(img_file1)
var params = new FormData()
params.append('image', img_file1)
params.append('client_name', this.tableSelected)
axios.post("api url", params,{ withCredentials: true },
{
headers:
{
"Content-Type": "application/json",
},
}).then(response =>{
console.log(response.data)→undefined
}).catch(function (error) {
console.log(error.status)
for(let key of Object.keys(error)) {
console.log(key);
console.log(error[key]);
}
});
},
app = Flask(__name__)
CORS(app)
@app.route('/', methods=['post'])
def upload_img():
if request.files.get('image'):
clientName = request.form.get('client_name')
uploadFile = request.files.get('image')
randlst_a = [random.choice(string.ascii_letters + string.digits) for i in range(10)]
radians_b = ''.join(randlst_a)
credential = service_account.Credentials.from_service_account_file(env variable)
project_id = "xxxxxxxxxxxxx"
bucket_name = "xxxxxxx"
fileName = str(clientName) + radians_b + ".jpg"
gcs_path = "img/{0}/{1}".format(clientName,fileName)
client = gcs.Client(project_id, credentials=credential)
client = gcs.Client(project_id)
bucket = client.get_bucket(bucket_name)
blob_gcs = bucket.blob(gcs_path)
blob_gcs.upload_from_string(uploadFile.read(), content_type=uploadFile.content_type)
imageURL = "xxxxxxxxxxxxxxxxxx")
response = Response(imageURL, 200)
response.headers['Access-Control-Allow-Origin'] = '*'
response.mimetype = "text/plain"
return response
if __name__ == "__main__":
app.run(debug=True)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
