Home
Find the answer to your question
Sample code for uploadFile using XML in Ruby. The code is provided by the eBay Third Party developer whose developer UserID is flow.
MIME_BOUNDARY = 'DAVE_RAWK_RULES_THE_MIMES' CRLF = '\r\n' def send_file(iJobId, iFileId, iCompressedFileName, iToken) uri = URI.parse('https://storage.ebay.com/FileTransferService') file = File.new(iCompressedFileName, 'rb') post_body = [] post_body << '--#{MIME_BOUNDARY}' + CRLF post_body << 'Content-Type: application/xop+xml; charset=UTF-8; type='text/xml; charset=UTF-8'' + CRLF post_body << 'Content-Transfer-Encoding: binary' + CRLF post_body << 'Content-ID: <urn:uuid:123456789>' + CRLF + CRLF post_body << '<?xml version='1.0' encoding='UTF-8'?>' post_body << '<uploadFileRequest xmlns:sct='http://www.ebay.com/soaframework/common/types' xmlns='http://www.ebay.com/marketplace/services'>' post_body << '<taskReferenceId>' + iJobId.to_s + '</taskReferenceId>' post_body << '<fileReferenceId>' + iFileId.to_s + '</fileReferenceId>' post_body << '<fileFormat>gzip</fileFormat>' post_body << '<fileAttachment>' post_body << '<Size>' +file.size.to_s+ '</Size>' post_body << '<Data><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:urn:uuid:ABCDEFGHIJKLMNOP' /></Data>' post_body << '</fileAttachment></uploadFileRequest>' + CRLF post_body << '--#{MIME_BOUNDARY}\r\n' post_body << 'Content-Type: application/octet-stream' + CRLF post_body << 'Content-Transfer-Encoding: binary' + CRLF post_body << 'Content-ID: <urn:uuid:ABCDEFGHIJKLMNOP>' + CRLF + CRLF post_body << file.read post_body << CRLF post_body << '--#{MIME_BOUNDARY}--' + CRLF req = Net::HTTP::Post.new(uri.request_uri) req.body = post_body.join req.add_field('X-EBAY-SOA-OPERATION-NAME', 'uploadFile') req.add_field('X-EBAY-SOA-SECURITY-TOKEN', iToken) req.add_field('X-EBAY-SOA-REQUEST-DATA-FORMAT', 'XML') req.add_field('X-EBAY-SOA-RESPONSE-DATA-FORMAT', 'XML') req.add_field('Cache-Control', 'no-cache') req.add_field('Pragma', 'no-cache') req.add_field('Connection', 'keep-alive') req.add_field('Content-type', 'multipart/related; boundary=#{MIME_BOUNDARY};type=\'application/xop+xml\';start=\'<urn:uuid:123456789>\';start-info=\'text/xml\'') req.add_field('Content-Length', req.body.size.to_s) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = 0 resp = http.request(req) end |