使用OCR将图片上传到Google云端硬盘,然后转换为Doc [英] Upload an image to Google Drive with OCR and convert to Doc

查看:84
本文介绍了使用OCR将图片上传到Google云端硬盘,然后转换为Doc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像上传到具有OCR功能的Google云端硬盘,然后将其转换为Google文档.我正在使用这种方法

I want to upload an image to Google Drive with OCR function and convert it to Google Doc. I am using this method

public static File UploadFile(DriveService Service, string UploadFile, string Parent)
    {

        if (System.IO.File.Exists(UploadFile))
        {
            File body = new File();
            body.Title = System.IO.Path.GetFileName(UploadFile);
            body.Description = "File uploaded by Diamto Drive Sample";
            body.MimeType = GetMimeType(UploadFile);
            body.Parents = new List<ParentReference>() { new ParentReference() { Id = Parent } };

            // File’s content.
            byte[] byteArray = System.IO.File.ReadAllBytes(UploadFile);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
            try
            {
                FilesResource.InsertMediaUpload request = Service.Files.Insert(body, stream, GetMimeType(UploadFile));
                request.Ocr = true;
                request.OcrLanguage = "he";
                request.Convert = true;
                return request.ResponseBody;
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: " + e.Message);
                return null;
            }
        }
        else
        {
            Console.WriteLine("File does not exist: " + UploadFile);
            return null;
        }

    }

我通过这行称呼它

Google.Apis.Drive.v2.Data.File newFile = DriveHelper.UploadFile(service, @"E:\myImage.png", myFolderId);

我的问题是: request.ResponseBody 返回 null ,但是当我删除这些行时

My problem is: request.ResponseBody returns null but when I remove this lines

 request.Ocr = true;
 request.OcrLanguage = "he";
 request.Convert = true;

我的文件成功上传和 request.ResponseBody 返回 File 对象

My file uploaded successfully and request.ResponseBody returns File Object

推荐答案

这缺少上载功能.

request.Upload();
return request.ResponseBody;

参考链接: http://anthonygiretti.com/category/google-api/

这篇关于使用OCR将图片上传到Google云端硬盘,然后转换为Doc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆