packageocrimport("context""fmt""log")// ProcessImage is executed when a file is uploaded to the Cloud Storage bucket you// created for uploading images. It runs detectText, which processes the image for text.funcProcessImage(ctxcontext.Context,eventGCSEvent)error{iferr:=setup(ctx);err!=nil{returnfmt.Errorf("ProcessImage: %v",err)}ifevent.Bucket==""{returnfmt.Errorf("empty file.Bucket")}ifevent.Name==""{returnfmt.Errorf("empty file.Name")}iferr:=detectText(ctx,event.Bucket,event.Name);err!=nil{returnfmt.Errorf("detectText: %v",err)}log.Printf("File %s processed.",event.Name)returnnil}
/** * This function is exported by index.js, and is executed when * a file is uploaded to the Cloud Storage bucket you created * for uploading images. * * @param {object} event A Google Cloud Storage File object. */exports.processImage=asyncevent=>{const{bucket,name}=event;if(!bucket){thrownewError('Bucket not provided. Make sure you have a "bucket" property in your request');}if(!name){thrownewError('Filename not provided. Make sure you have a "name" property in your request');}awaitdetectText(bucket,name);console.log(`File ${name} processed.`);};
defprocess_image(file,context):"""Cloud Function triggered by Cloud Storage when a file is changed. Args: file (dict): Metadata of the changed file, provided by the triggering Cloud Storage event. context (google.cloud.functions.Context): Metadata of triggering event. Returns: None; the output is written to stdout and Stackdriver Logging """bucket=validate_message(file,"bucket")name=validate_message(file,"name")detect_text(bucket,name)print("File {} processed.".format(file["name"]))
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],[],[],[]]