22 * Xero Files API
33 * These endpoints are specific to Xero Files API
44 *
5- * The version of the OpenAPI document: 2.10.1
5+ * The version of the OpenAPI document: 2.10.2
6677 *
88 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -1493,14 +1493,13 @@ public HttpResponse updateFolderForHttpResponse(
14931493 }
14941494
14951495 /**
1496- * Uploads a File
1496+ * Uploads a File to the inbox
14971497 *
14981498 * <p><b>201</b> - A successful request
14991499 *
15001500 * <p><b>400</b> - invalid input, object invalid
15011501 *
15021502 * @param xeroTenantId Xero identifier for Tenant
1503- * @param folderId pass an optional folder id to save file to specific folder
15041503 * @param body The body parameter
15051504 * @param name exact name of the file you are uploading
15061505 * @param filename The filename parameter
@@ -1512,7 +1511,6 @@ public HttpResponse updateFolderForHttpResponse(
15121511 public FileObject uploadFile (
15131512 String accessToken ,
15141513 String xeroTenantId ,
1515- UUID folderId ,
15161514 File body ,
15171515 String name ,
15181516 String filename ,
@@ -1521,8 +1519,7 @@ public FileObject uploadFile(
15211519 try {
15221520 TypeReference <FileObject > typeRef = new TypeReference <FileObject >() {};
15231521 HttpResponse response =
1524- uploadFileForHttpResponse (
1525- accessToken , xeroTenantId , folderId , body , name , filename , mimeType );
1522+ uploadFileForHttpResponse (accessToken , xeroTenantId , body , name , filename , mimeType );
15261523 return apiClient .getObjectMapper ().readValue (response .getContent (), typeRef );
15271524 } catch (HttpResponseException e ) {
15281525 if (logger .isDebugEnabled ()) {
@@ -1541,14 +1538,13 @@ public FileObject uploadFile(
15411538 }
15421539
15431540 /**
1544- * Uploads a File
1541+ * Uploads a File to the inbox
15451542 *
15461543 * <p><b>201</b> - A successful request
15471544 *
15481545 * <p><b>400</b> - invalid input, object invalid
15491546 *
15501547 * @param xeroTenantId Xero identifier for Tenant
1551- * @param folderId pass an optional folder id to save file to specific folder
15521548 * @param body The body parameter
15531549 * @param name exact name of the file you are uploading
15541550 * @param filename The filename parameter
@@ -1560,7 +1556,6 @@ public FileObject uploadFile(
15601556 public HttpResponse uploadFileForHttpResponse (
15611557 String accessToken ,
15621558 String xeroTenantId ,
1563- UUID folderId ,
15641559 File body ,
15651560 String name ,
15661561 String filename ,
@@ -1580,18 +1575,149 @@ public HttpResponse uploadFileForHttpResponse(
15801575 headers .setAccept ("application/json" );
15811576 headers .setUserAgent (this .getUserAgent ());
15821577 UriBuilder uriBuilder = UriBuilder .fromUri (apiClient .getBasePath () + "/Files" );
1583- if (folderId != null ) {
1584- String key = "FolderId" ;
1585- Object value = folderId ;
1586- if (value instanceof Collection ) {
1587- uriBuilder = uriBuilder .queryParam (key , ((Collection ) value ).toArray ());
1588- } else if (value instanceof Object []) {
1589- uriBuilder = uriBuilder .queryParam (key , (Object []) value );
1590- } else {
1591- uriBuilder = uriBuilder .queryParam (key , value );
1578+ String url = uriBuilder .build ().toString ();
1579+ GenericUrl genericUrl = new GenericUrl (url );
1580+ if (logger .isDebugEnabled ()) {
1581+ logger .debug ("POST " + genericUrl .toString ());
1582+ }
1583+
1584+ Map <String , String > parameters = Maps .newHashMap ();
1585+ parameters .put ("name" , name );
1586+ parameters .put ("filename" , filename );
1587+
1588+ // Add parameters
1589+ MultipartContent content =
1590+ new MultipartContent ()
1591+ .setMediaType (
1592+ new HttpMediaType ("multipart/form-data" )
1593+ .setParameter ("boundary" , "__END_OF_PART__" ));
1594+
1595+ for (String key : parameters .keySet ()) {
1596+ MultipartContent .Part part =
1597+ new MultipartContent .Part (new ByteArrayContent (null , parameters .get (key ).getBytes ()));
1598+ part .setHeaders (
1599+ new HttpHeaders ()
1600+ .set ("Content-Disposition" , String .format ("form-data; name=\" %s\" " , key )));
1601+ content .addPart (part );
1602+ }
1603+
1604+ FileContent fileContent = new FileContent (mimeType , body );
1605+ MultipartContent .Part part = new MultipartContent .Part (fileContent );
1606+ part .setHeaders (
1607+ new HttpHeaders ()
1608+ .set (
1609+ "Content-Disposition" ,
1610+ String .format ("form-data; name=\" content\" ; filename=\" %s\" " , filename )));
1611+ content .addPart (part );
1612+ Credential credential =
1613+ new Credential (BearerToken .authorizationHeaderAccessMethod ()).setAccessToken (accessToken );
1614+ HttpTransport transport = apiClient .getHttpTransport ();
1615+ HttpRequestFactory requestFactory = transport .createRequestFactory (credential );
1616+ return requestFactory
1617+ .buildRequest (HttpMethods .POST , genericUrl , content )
1618+ .setHeaders (headers )
1619+ .setConnectTimeout (apiClient .getConnectionTimeout ())
1620+ .setReadTimeout (apiClient .getReadTimeout ())
1621+ .execute ();
1622+ }
1623+
1624+ /**
1625+ * Uploads a File to a specific folder
1626+ *
1627+ * <p><b>201</b> - A successful request
1628+ *
1629+ * <p><b>400</b> - invalid input, object invalid
1630+ *
1631+ * @param xeroTenantId Xero identifier for Tenant
1632+ * @param folderId pass required folder id to save file to specific folder
1633+ * @param body The body parameter
1634+ * @param name exact name of the file you are uploading
1635+ * @param filename The filename parameter
1636+ * @param mimeType The mimeType parameter
1637+ * @param accessToken Authorization token for user set in header of each request
1638+ * @return FileObject
1639+ * @throws IOException if an error occurs while attempting to invoke the API *
1640+ */
1641+ public FileObject uploadFileToFolder (
1642+ String accessToken ,
1643+ String xeroTenantId ,
1644+ UUID folderId ,
1645+ File body ,
1646+ String name ,
1647+ String filename ,
1648+ String mimeType )
1649+ throws IOException {
1650+ try {
1651+ TypeReference <FileObject > typeRef = new TypeReference <FileObject >() {};
1652+ HttpResponse response =
1653+ uploadFileToFolderForHttpResponse (
1654+ accessToken , xeroTenantId , folderId , body , name , filename , mimeType );
1655+ return apiClient .getObjectMapper ().readValue (response .getContent (), typeRef );
1656+ } catch (HttpResponseException e ) {
1657+ if (logger .isDebugEnabled ()) {
1658+ logger .debug (
1659+ "------------------ HttpResponseException "
1660+ + e .getStatusCode ()
1661+ + " : uploadFileToFolder -------------------" );
1662+ logger .debug (e .toString ());
15921663 }
1664+ XeroApiExceptionHandler handler = new XeroApiExceptionHandler ();
1665+ handler .execute (e );
1666+ } catch (IOException ioe ) {
1667+ throw ioe ;
15931668 }
1594- String url = uriBuilder .build ().toString ();
1669+ return null ;
1670+ }
1671+
1672+ /**
1673+ * Uploads a File to a specific folder
1674+ *
1675+ * <p><b>201</b> - A successful request
1676+ *
1677+ * <p><b>400</b> - invalid input, object invalid
1678+ *
1679+ * @param xeroTenantId Xero identifier for Tenant
1680+ * @param folderId pass required folder id to save file to specific folder
1681+ * @param body The body parameter
1682+ * @param name exact name of the file you are uploading
1683+ * @param filename The filename parameter
1684+ * @param mimeType The mimeType parameter
1685+ * @param accessToken Authorization token for user set in header of each request
1686+ * @return HttpResponse
1687+ * @throws IOException if an error occurs while attempting to invoke the API
1688+ */
1689+ public HttpResponse uploadFileToFolderForHttpResponse (
1690+ String accessToken ,
1691+ String xeroTenantId ,
1692+ UUID folderId ,
1693+ File body ,
1694+ String name ,
1695+ String filename ,
1696+ String mimeType )
1697+ throws IOException {
1698+ // verify the required parameter 'xeroTenantId' is set
1699+ if (xeroTenantId == null ) {
1700+ throw new IllegalArgumentException (
1701+ "Missing the required parameter 'xeroTenantId' when calling uploadFileToFolder" );
1702+ } // verify the required parameter 'folderId' is set
1703+ if (folderId == null ) {
1704+ throw new IllegalArgumentException (
1705+ "Missing the required parameter 'folderId' when calling uploadFileToFolder" );
1706+ }
1707+ if (accessToken == null ) {
1708+ throw new IllegalArgumentException (
1709+ "Missing the required parameter 'accessToken' when calling uploadFileToFolder" );
1710+ }
1711+ HttpHeaders headers = new HttpHeaders ();
1712+ headers .set ("xero-tenant-id" , xeroTenantId );
1713+ headers .setAccept ("application/json" );
1714+ headers .setUserAgent (this .getUserAgent ());
1715+ // create a map of path variables
1716+ final Map <String , Object > uriVariables = new HashMap <String , Object >();
1717+ uriVariables .put ("FolderId" , folderId );
1718+
1719+ UriBuilder uriBuilder = UriBuilder .fromUri (apiClient .getBasePath () + "/Folders/{FolderId}" );
1720+ String url = uriBuilder .buildFromMap (uriVariables ).toString ();
15951721 GenericUrl genericUrl = new GenericUrl (url );
15961722 if (logger .isDebugEnabled ()) {
15971723 logger .debug ("POST " + genericUrl .toString ());
0 commit comments