vb.net - Google Drive Rest: convert does not work -


i using g drive rest endpoints (not .net client) upload docx files through vb .net. problem if declare query parameter "convert" true, files getting uploaded never auto-convert. first thing create new file post , after upload content put in upload uri in separate request.

it not work when use google playground upload docx files.

      public shared function uploadstream(filestream io.stream, filename string, mimetype string, target string, accesstoken string, optional converttogdoc boolean = false) string     try          dim subject string = ""         dim doc new aspose.words.document         dim docformat = aspose.words.fileformatutil.detectfileformat(filestream) ' detect format of file 'check if file doc or docx         if docformat.loadformat = aspose.words.loadformat.doc or docformat.loadformat = aspose.words.loadformat.docx 'check if file word document             doc = new aspose.words.document(filestream)             subject = doc.builtindocumentproperties.subject 'get subject word file             if doc.builtindocumentproperties.subject = "" subject = "none"         else             subject = "none" 'set subject none if file not word file         end if          dim localmd5 = files.md5stream(filestream)          dim baseaddress = "https://www.googleapis.com/drive/v2/files?convert=" + converttogdoc.tostring         dim req = net.httpwebrequest.create(baseaddress)         req.method = "post"         req.headers.add("authorization", "bearer " + system.web.httputility.urlencode(accesstoken))         req.contenttype = "application/json"          dim writer = new newtonsoft.json.linq.jtokenwriter()         writer.writestartobject()         writer.writepropertyname("title")         writer.writevalue(filename)          writer.writepropertyname("parents")         writer.writestartarray()         writer.writerawvalue("{'id':'" + target + "'}")         writer.writeendarray()         writer.writepropertyname("properties")         writer.writestartarray()         writer.writerawvalue("{'key':'subject','value':'" + subject + "'},{'key':'md5','value':'" + localmd5 + "'},{'key':'author','value':''}")         writer.writeendarray()         writer.writeendobject()          dim bodybytes = text.encoding.utf8.getbytes(writer.token.tostring)         req.contentlength = bodybytes.length          dim requeststream = req.getrequeststream         requeststream.write(bodybytes, 0, bodybytes.length)         requeststream.close()          dim resp system.net.httpwebresponse = req.getresponse()         dim response = new io.streamreader(resp.getresponsestream, false).readtoend         dim json newtonsoft.json.linq.jobject         json = newtonsoft.json.linq.jobject.parse(response)         dim fileid = json.selecttoken("id").tostring()          baseaddress = "https://www.googleapis.com/upload/drive/v2/files/" + fileid + "?uploadtype=media&convert=" + converttogdoc.tostring         req = net.httpwebrequest.create(baseaddress)         req.method = "put"         req.headers.add("authorization", "bearer " + system.web.httputility.urlencode(accesstoken))         bodybytes = general.getstreamasbytearray(filestream)          req.contentlength = bodybytes.length          req.contenttype = mimetype          requeststream = req.getrequeststream         requeststream.write(bodybytes, 0, bodybytes.length)         requeststream.close()         resp = req.getresponse()         response = new io.streamreader(resp.getresponsestream, false).readtoend          return fileid     catch ex exception         return nothing     end try end function  shared function getstreamasbytearray(byval stream system.io.stream) byte()     dim streamlength integer = convert.toint32(stream.length)      dim filedata byte() = new byte(streamlength) {}     stream.position = 0     ' read file byte array       stream.read(filedata, 0, streamlength)      stream.close()     redim preserve filedata(filedata.length - 2)     return filedata   end function   public shared function md5stream(byval file_stream io.stream, optional byval seperator string = nothing) string     using md5 new system.security.cryptography.md5cryptoserviceprovider         dim hash() byte = md5.computehash(file_stream)         return replace(bitconverter.tostring(hash), "-", seperator)     end using end function 

had else same problem?


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -