使用IDS V3将文件上传到Quickbooks [英] Upload File to Quickbooks online with IDS V3

查看:169
本文介绍了使用IDS V3将文件上传到Quickbooks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用IDS V3将文件上传到QuickBooks Online。
我按照这里描述的步骤
https:// developer .intuit.com /文档/ 0025_quickbooksapi / 0050_data_services / 020_key_concepts /附件
这是我的源代码

$ p $ URL url = new URL(https://quickbooks.api.intuit。 COM / V3 /公司/ My_company_ID /上传);
HttpURLConnection request =(HttpURLConnection)url.openConnection();
request.setDoOutput(true);
request.setRequestMethod(POST);
HttpParameters para = new HttpParameters();
// String status = URLEncoder.encode(中文,utf-8)。replaceAll(\\ +,%20);
//para.put(\"status,status);
String boundary =--------------------------- 37531613912423;
// String content = - + boundary +\r\\\
Content-Disposition:form-data; name = \status \\r\\\
\r\\\
;
String pic =\r\\\
- + boundary +\r\\\
Content-Disposition:form-data; name = \pic\; filename = \postpic。 gif \\r\\\
Content-Type:image / gif\r\\\
\r\\\
;
byte [] end_data =(\r\\\
--+ boundary +--\r\\\
)。getBytes();
文件f =新文件(/ Users / cnanfack / Documents / oml_map1.gif);
FileInputStream stream = new FileInputStream(f);
byte [] file = new byte [(int)f.length()];
stream.read(file);
String lineEnd =\r\\\
;
String header =Content-Disposition:form-data; name = \file_metadata_0\+ lineEnd
+Content-Type:application / xml; charset = UTF-8+ lineEnd
+Content-Transfer-Encoding:8bit+ lineEnd;

String attachchable = header +<?xml version = \1.0 \encoding = \UTF-8 \standalone = \yes\?><< ;可附加xmlns = \http://schema.intuit.com/finance/v3\domain = \QBO \sparse = \false \>
+< EntityRef type = \Bill \> 285< / EntityRef>
+<大小> 4099< /大小>
+< ContentType> image / gif< / ContentType>
+< FileName> postpic.gif< / FileName>
+< /可附加>;

request.setRequestProperty(Content-Type,multipart / form-data; boundary =+ boundary);
//request.setRequestProperty(\"Content-Length,String.valueOf(boundary.getBytes()。length +test.getBytes()。length + pic.getBytes()。length + f.length() + end_data.length));
//consumer.setAdditionalParameters(para);
consumer.sign(request);
OutputStream ot = request.getOutputStream();
ot.write(end_data);
ot.write(attachable.getBytes());
ot.write(end_data);
//ot.write(status.getBytes());
ot.write(pic.getBytes());
ot.write(Content-Transfer-Encoding:binary \r\\\
\r\\\
.getBytes());
ot.write(file);
ot.write(end_data);
ot.flush();
ot.close();
System.err.println(正在发送请求...);
request.connect();
System.err.println(Response:+ request.getResponseCode()+
+ request.getResponseMessage());
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
String b = null; ((b = reader.readLine())!= null){
System.err.println(b);



$ b

返回结果:

 响应:200 OK 
<?xml version =1.0encoding =UTF-8standalone =yes?>< IntuitResponse xmlns = http://schema.intuit.com/finance/v3time =2013-11-10T20:24:27.823-08:00/>

但是我在Quickbooks Online上看不到该文件。
也许我想念一些东西。有人能帮我吗?
预先感谢您

解决方案

我曾尝试使用Java Devkit进行上传端点调用。它工作正常。 PFB明细。

   - 请求网址:https://quickbooks.api.intuit.com/v3/company/688779980/upload ? Http 
- 方法:POST内容处理:form-data; name =file_metadata_2bddf
- Content-Type:application / xml

<?xml version =1.0encoding =UTF-8standalone =yes?>
<可附加xmlns =http://schema.intuit.com/finance/v3>
< FileName> images.jpg< / FileName>
< ContentType>图片/ jpeg< / ContentType>
< Lat> 25.293112341223< / Lat>
< Long> -21.3253249834< / Long>
< PlaceName>假地点< / PlaceName>
< Note>可附注900a49e1< / Note>
< Tag>可附加标签900a49e1< / Tag>
< /可附加>

响应XML

 <?xml version =1.0encoding =UTF-8standalone =yes?> 
< IntuitResponse xmlns =http://schema.intuit.com/finance/v3time =2013-11-12T05:58:25.296-08:00>
< AttachableResponse>
<可附加域名=QBOsparse =false>
< Id> 100000000000543524< / Id>
< SyncToken> 0< / SyncToken>
<元数据>
< CreateTime> 2013-11-12T05:58:26-08:00< / CreateTime>
< LastUpdatedTime> 2013-11-12T05:58:26-08:00< / LastUpdatedTime>
< / MetaData>
< FileName> images.jpg< / FileName>
< FileAccessUri> / v3 / company / 688779980 / download / 100000000000543524< / FileAccessUri>
将TempDownloadUri> HTTPS:?//intuit-qbo-prod-19.s3.amazonaws.com/688779980%2Fattachments%2Fimages-1384264705362.jpg过期= 1384265606&放大器;放大器; AWSAccessKeyId = AKIAJEXDXKNYCBUNCCCQ&放大器;放大器;签名= ESZPzeO%2B5YWxw8VOWMVMBRnvIdw%3D< / TempDownloadUri>
< Size> 58616< / Size>
< ContentType>图片/ jpeg< / ContentType>
< Lat> 25.293112341223< / Lat>
< Long> -21.3253249834< / Long>
< PlaceName>假地点< / PlaceName>
< Note>可附注8219e79a< / Note>
< Tag>可附加标签8219e79a< / Tag>
< ThumbnailFileAccessUri> / v3 / company / 688779980 / attachable-thumbnail / 100000000000543524< / ThumbnailFileAccessUri>
< /可附加>
< / AttachableResponse>
< / IntuitResponse>

从ThumnailFileAccessUri属性中,我得到了我用于下载端点的以下附件URI。



/ v3 / company / 688779980 / attachchable-thumbnail / 100000000000543524

下载终端(GET) -

b
$ b

  https://quickbooks.api.intuit.com/v3/company/688779980/download/100000000000543521 

JAVA / .Net SDK下载链接 - https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits



希望这会有用

编辑 - 添加Java代码片段

  public static void executeUploadForImageFilePoc(DataService service)throws ParseException,FMSException,FileNotFoundException {
System.out.println(executeUploadForImageFile);
String uuid = UUID.randomUUID()。toString()。substring(0,8);
可附加的附件1 =新的附件();
//attachable.setSize(new Long(34234));
attachable1.setLat(25.293112341223);
attachable1.setLong( - 21.3253249834);
attachable1.setPlaceName(Fake Place);
attachable1.setNote(可附注+ uuid);
attachable1.setTag(可附加标签+ uuid);
可附加的attachchable = attachable1;
attachable.setFileName(images.jpg);
attachable.setContentType(image / jpeg);
档案档案=新档案(C:\\images_new.jpg);
InputStream in = new FileInputStream(file);

//上传端点呼叫
可附加的attachableOutput = service.upload(可附着,in);

//检查返回XML
attachchable.getFileAccessUri();
System.out.println(attachableOutput.getFileAccessUri());
System.out.println(attachableOutput.getFileName());

//下载端点调用
InputStream output = service.download(attachableOutput);
尝试{
BufferedImage bImageFromConvert = ImageIO.read(output);

ImageIO.write(bImageFromConvert,jpg,new File(C:\\images_new_manas.jpg));
$ b $ catch(IOException e){
抛出新的FMSException(读取上传文件时出错,e);




$ p感谢

I would like to upload a file to QuickBooks Online using IDS V3. I followed the steps described here https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/020_key_concepts/attachments. Here is my source code

 URL url = new URL("https://quickbooks.api.intuit.com/v3/company/My_company_ID/upload");
    HttpURLConnection request = (HttpURLConnection) url.openConnection();
    request.setDoOutput(true);
    request.setRequestMethod("POST");
    HttpParameters para = new HttpParameters();
    //String status = URLEncoder.encode("中 文","utf-8").replaceAll("\\+", "%20");
    //para.put("status", status);
    String boundary = "---------------------------37531613912423";
    //String content = "--"+boundary+"\r\nContent-Disposition: form-data; name=\"status\"\r\n\r\n";
    String pic = "\r\n--"+boundary+"\r\nContent-Disposition: form-data; name=\"pic\"; filename=\"postpic.gif\"\r\nContent-Type: image/gif\r\n\r\n";
    byte[] end_data = ("\r\n--" + boundary + "--\r\n").getBytes();  
    File f = new File("/Users/cnanfack/Documents/oml_map1.gif");
    FileInputStream stream = new FileInputStream(f);
    byte[] file = new byte[(int)f.length()];
    stream.read(file);
    String lineEnd = "\r\n";
    String header =   "Content-Disposition: form-data; name=\"file_metadata_0\""+lineEnd
    +"Content-Type: application/xml; charset=UTF-8"+lineEnd
    +"Content-Transfer-Encoding: 8bit"+lineEnd;

   String attachable =  header+"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Attachable xmlns=\"http://schema.intuit.com/finance/v3\" domain=\"QBO\" sparse=\"false\">"
    +"<EntityRef type=\"Bill\">285</EntityRef>"
    +"<Size>4099</Size>"
    +"<ContentType>image/gif</ContentType>"
    +"<FileName>postpic.gif</FileName>"
    +"</Attachable>";

    request.setRequestProperty("Content-Type", "multipart/form-data; boundary="+boundary); 
    //request.setRequestProperty("Content-Length", String.valueOf(boundary.getBytes().length+"test".getBytes().length+pic.getBytes().length+f.length()+end_data.length)); 
    //consumer.setAdditionalParameters(para);
      consumer.sign(request);
      OutputStream ot = request.getOutputStream();
      ot.write(end_data);
      ot.write(attachable.getBytes());
      ot.write(end_data);
      //ot.write(status.getBytes());
      ot.write(pic.getBytes());
      ot.write("Content-Transfer-Encoding: binary\r\n\r\n".getBytes());
      ot.write(file);
      ot.write(end_data);
      ot.flush();
      ot.close();
    System.err.println("Sending request...");
    request.connect();
    System.err.println("Response: " + request.getResponseCode() + " "
          + request.getResponseMessage());
    BufferedReader reader =new BufferedReader(new InputStreamReader(request.getInputStream()));
    String b = null;
    while((b = reader.readLine())!=null){
       System.err.println(b);
    }

The returned result:

Response: 200 OK
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2013-11-10T20:24:27.823-08:00"/>

But I don't see the file on Quickbooks Online. Maybe I miss something. Can someone help me? Thank you in advance

解决方案

I had tried this Upload endpoint call using Java Devkit. It is working fine. PFB details.

 -  Request URI : https://quickbooks.api.intuit.com/v3/company/688779980/upload? Http
 -  Method : POST Content-Disposition: form-data; name="file_metadata_2bddf" 
 -  Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Attachable xmlns="http://schema.intuit.com/finance/v3">
    <FileName>images.jpg</FileName>
    <ContentType>image/jpeg</ContentType>
    <Lat>25.293112341223</Lat>
    <Long>-21.3253249834</Long>
    <PlaceName>Fake Place</PlaceName>
    <Note>Attachable note 900a49e1</Note>
    <Tag>Attachable tag 900a49e1</Tag>
</Attachable>

Response XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2013-11-12T05:58:25.296-08:00">
    <AttachableResponse>
        <Attachable domain="QBO" sparse="false">
            <Id>100000000000543524</Id>
            <SyncToken>0</SyncToken>
            <MetaData>
                <CreateTime>2013-11-12T05:58:26-08:00</CreateTime>
                <LastUpdatedTime>2013-11-12T05:58:26-08:00</LastUpdatedTime>
            </MetaData>
            <FileName>images.jpg</FileName>
            <FileAccessUri>/v3/company/688779980/download/100000000000543524</FileAccessUri>
            <TempDownloadUri>https://intuit-qbo-prod-19.s3.amazonaws.com/688779980%2Fattachments%2Fimages-1384264705362.jpg?Expires=1384265606&amp;AWSAccessKeyId=AKIAJEXDXKNYCBUNCCCQ&amp;Signature=ESZPzeO%2B5YWxw8VOWMVMBRnvIdw%3D</TempDownloadUri>
            <Size>58616</Size>
            <ContentType>image/jpeg</ContentType>
            <Lat>25.293112341223</Lat>
            <Long>-21.3253249834</Long>
            <PlaceName>Fake Place</PlaceName>
            <Note>Attachable note 8219e79a</Note>
            <Tag>Attachable tag 8219e79a</Tag>
            <ThumbnailFileAccessUri>/v3/company/688779980/attachable-thumbnail/100000000000543524</ThumbnailFileAccessUri>
        </Attachable>
    </AttachableResponse>
</IntuitResponse>

From the ThumnailFileAccessUri property I got the following attachment URI which I had used for Download endpoint.

/v3/company/688779980/attachable-thumbnail/100000000000543524

Download Endpoint(GET)-

https://quickbooks.api.intuit.com/v3/company/688779980/download/100000000000543521

JAVA/.Net SDK download link - https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits

Hope it will be useful.

EDIT- Adding Java code snippet

public static void executeUploadForImageFilePoc(DataService service) throws ParseException, FMSException, FileNotFoundException {
    System.out.println("executeUploadForImageFile");
    String uuid = UUID.randomUUID().toString().substring(0, 8);
    Attachable attachable1 = new Attachable();
    //attachable.setSize(new Long("34234"));
    attachable1.setLat("25.293112341223");
    attachable1.setLong("-21.3253249834");
    attachable1.setPlaceName("Fake Place");
    attachable1.setNote("Attachable note " + uuid);
    attachable1.setTag("Attachable tag " + uuid);
    Attachable attachable = attachable1;
    attachable.setFileName("images.jpg");
    attachable.setContentType("image/jpeg");
    File file = new File("C:\\images_new.jpg");
    InputStream in = new FileInputStream(file);

    //Upload endpoint call
    Attachable attachableOutput = service.upload(attachable, in);

    //Check return XML
    attachable.getFileAccessUri();
    System.out.println(attachableOutput.getFileAccessUri());
    System.out.println(attachableOutput.getFileName());

    //Download endpoint call
    InputStream output = service.download(attachableOutput);
    try {
        BufferedImage bImageFromConvert = ImageIO.read(output);

        ImageIO.write(bImageFromConvert, "jpg", new File("C:\\images_new_manas.jpg"));

    } catch (IOException e) {
        throw new FMSException("Error while reading the upload file.", e);
    }
}

Thanks

这篇关于使用IDS V3将文件上传到Quickbooks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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