0

File Transfer API

Hello,

I am using file transfer API in c# desktop appliaction.I did all the step which is described in API documents.After getting file receive notification, I send the actual data of the file that time [b ]Error 500 Service Error - Invalid or missing token[/b] is comes.

code :-


string aYahooContactID = "xyz";
string sendFile_realm = relayIP + "/relay";
string url = "http://" + sendFile_realm + "?&token=" + objFile.Token + "&sender=" + primaryLoginId + "&receiver=" + aYahooContactID + "&sid=" +sessionId+ "&oauth_consumer_key=" + oauth_consumer_key + "&oauth_signature_method=" + oauth_signature_method + "&oauth_nonce=" + oauth_nonce + "&oauth_timestamp=" + oauth_timestamp + "&oauth_signature=" + oauth_signature + "&oauth_version=" + oauth_version + "&oauth_token=" + oauth_token;
byte[] fileArr = GetFileByteArray(usersFile);
UploadFile(url, fileArr);



private byte[] GetFileByteArray(string filename)
{

FileStream oFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);

//Create a byte array of file size.
byte[] FileByteArrayData = new byte[oFileStream.Length];

// Read file in bytes from stream into the byte array
oFileStream.Read(FileByteArrayData, 0, System.Convert.ToInt32(oFileStream.Length));

// Close the File Stream
oFileStream.Close();
return FileByteArrayData; //return the byte data

}

public string UploadFile(string URL, byte[] FileData)
{
string Response = null;
HttpWebRequest WebReq = null;
HttpWebResponse WebRes = null;
StreamReader StreamResponseReader = null;
Stream requestStream = null;
try
{
WebReq = (HttpWebRequest)WebRequest.Create(URL);
WebReq.Method = "POST";
WebReq.Accept = "*/*";

// WebReq.Connection = "Close";
WebReq.AllowAutoRedirect = false;
// WebReq.AllowWriteStreamBuffering = true;
WebReq.ContentType = "text/html";// "binary/octet-stream";
WebReq.ContentLength = FileData.Length;
WebReq.UserAgent = "Mozilla/5.0";




requestStream = WebReq.GetRequestStream();
requestStream.Write(FileData, 0, FileData.Length);

requestStream.Flush();
requestStream.Close();

WebRes = (HttpWebResponse)WebReq.GetResponse();
StreamResponseReader = new StreamReader(WebRes.GetResponseStream(), Encoding.UTF8);
Response = StreamResponseReader.ReadToEnd();
Notify();
}
catch (WebException ex)
{
MessageBox.Show(ex.Message.ToString());
Console.WriteLine(ex.Message.ToString());
}
finally
{
if (WebReq != null)
{
WebReq.Abort();
WebReq = null;
}
if (WebRes != null)
{
WebRes.Close();
WebRes = null;
}
if (StreamResponseReader != null)
{
StreamResponseReader.Close();
StreamResponseReader = null;
}
if (requestStream != null)
{
requestStream = null;
}
}


return Response;
}




please guide me.
Thanks

by
6 Replies
  • i am getting error while doing the file transfer invite., if i can get this working, then i can proceed to the next step, of sending the file, or doing accept/decline.

    Please find the request/response that i am doing, and let me know what wrong i am doing.


    Request:

    CODE
    POST http://rcore1.messenger.yahooapis.com/v1/filetransfer/relay?oauth_consumer_key=STRIPPED&oauth_nonce=8fbeb9ab-6ab7-41a8-bf28-aab1afce02d8&oauth_signature=STRIPPED&oauth_signature_method=PLAINTEXT&oauth_timestamp=1297014473&oauth_token=A%3DGzDK662R5zvkUDRNl.ahPQASAU06xiv3hJZwuR9fXK0qpm8EfIQijoh96vsoW9NzWaN6yAXV59VhbY
    MrXKU5FKRKe3NlBuUSmQQJW6lZreEKEU2wIbmI0dFIBohlC9CEKizR7LLNaERP_S05lz_8rNhb3f.MU8i
    zNGTqmrXwkLyeCpcrcAuS_8VLa5ZETE0LbRX59zbvk2PQxmKbQVX6lAeNabw57WpkjRUkyHRXe_qIsDYF
    Naz9Ac99UCrJ2QqS85WWOBrodl6RBO2dPAeFvJyBv0NRjwGDFNUx_GC.Zo2o_Vwf4HVuly_L0e1j3Ar.2
    3zjknarcka7e9rzL0VZXqgmAH6iUszlVWH46ivsOxVHPszM7eGqpwggl6AWTqoEx9T.iO_rRnUm.fmfj0
    A_iz9bBZZqt0T1j4Drh1jugdsiwFgMi3.NRIoyotrtDqhhn2FMFcWZs04PemYDQraPszDJlfztObVWfI3
    4ytwfDJWimVg7lRnLDJKHo9M.sgzbMZ8y1QKdMwadRTj.fDVpbMSx5.2kbDqEzK_a2CdEfyKgrlIQ4mpm
    JJt3y9tKFTh3Oun3IlyIrGbQmkvUa1epboKM0qMcJQHak.GdtTLBy1vbHzxaugFy7n5wfYzfoa8PX6kwi
    kfw9IzIstAb_po93ulNlgKUD.SJ9xJ63CH395GWjch1DsYDs4qbCFdr5W2sbR_r25_LEi.kboQ8MqCh38
    vLMDYq6R0zGDVc1o.UBxBDbn5zbR.NZUYID2wKaQKEta2eJXffJClFKvp4021IlQTzJHS94K.vIkBnTQ2
    CNfQy&oauth_version=1.0&sid=v2hChWPs3RN1VPOCOv3iEZDLv3p764g5fir9EQ-- HTTP/1.1
    Content-Type: application/json; charset=utf-8
    Host: rcore1.messenger.yahooapis.com
    Content-Length: 146
    Expect: 100-continue

    {"sendAs":"my_sender_here","action":"invite","ftSessionId":"FILE-TO-TRANSFER","target":"my_target_here","files":[{"fileName":"file.xml","fileSize":65}]}



    Response:
    CODE
    HTTP/1.1 403 Forbidden
    Date: Sun, 06 Feb 2011 17:46:19 GMT
    P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    cache-control: public,must-revalidate
    content-length: 110
    content-type: application/json;charset=utf-8
    Vary: Accept-Encoding
    Connection: close

    {"error":{"code":-1009,"detail":"Capability Check Error","description":"Capability Check Error"},"code":-1009}
    0
  • Hello,

    Did you set clientCapability in Session Management API.If not then first you have to set then you can send file.

    for ex.
    string postdatas = "{\"presenceState\":0,\"presenceMessage\":\"my login status message\",\"clientCapabilities\":[{\"clientCapability\":\"fileXfer\"}]}";

    Thanks


    QUOTE (Harshil Patel @ Feb 6 2011, 09:56 AM) <{POST_SNAPBACK}>
    i am getting error while doing the file transfer invite., if i can get this working, then i can proceed to the next step, of sending the file, or doing accept/decline.

    Please find the request/response that i am doing, and let me know what wrong i am doing.


    Request:

    CODE
    POST http://rcore1.messenger.yahooapis.com/v1/filetransfer/relay?oauth_consumer_key=STRIPPED&oauth_nonce=8fbeb9ab-6ab7-41a8-bf28-aab1afce02d8&oauth_signature=STRIPPED&oauth_signature_method=PLAINTEXT&oauth_timestamp=1297014473&oauth_token=A%3DGzDK662R5zvkUDRNl.ahPQASAU06xiv3hJZwuR9fXK0qpm8EfIQijoh96vsoW9NzWaN6yAXV59VhbY
    MrXKU5FKRKe3NlBuUSmQQJW6lZreEKEU2wIbmI0dFIBohlC9CEKizR7LLNaERP_S05lz_8rNhb3f.MU8
    i
    zNGTqmrXwkLyeCpcrcAuS_8VLa5ZETE0LbRX59zbvk2PQxmKbQVX6lAeNabw57WpkjRUkyHRXe_qIsDY
    F
    Naz9Ac99UCrJ2QqS85WWOBrodl6RBO2dPAeFvJyBv0NRjwGDFNUx_GC.Zo2o_Vwf4HVuly_L0e1j3Ar.
    2
    3zjknarcka7e9rzL0VZXqgmAH6iUszlVWH46ivsOxVHPszM7eGqpwggl6AWTqoEx9T.iO_rRnUm.fmfj
    0
    A_iz9bBZZqt0T1j4Drh1jugdsiwFgMi3.NRIoyotrtDqhhn2FMFcWZs04PemYDQraPszDJlfztObVWfI
    3
    4ytwfDJWimVg7lRnLDJKHo9M.sgzbMZ8y1QKdMwadRTj.fDVpbMSx5.2kbDqEzK_a2CdEfyKgrlIQ4mp
    m
    JJt3y9tKFTh3Oun3IlyIrGbQmkvUa1epboKM0qMcJQHak.GdtTLBy1vbHzxaugFy7n5wfYzfoa8PX6kw
    i
    kfw9IzIstAb_po93ulNlgKUD.SJ9xJ63CH395GWjch1DsYDs4qbCFdr5W2sbR_r25_LEi.kboQ8MqCh3
    8
    vLMDYq6R0zGDVc1o.UBxBDbn5zbR.NZUYID2wKaQKEta2eJXffJClFKvp4021IlQTzJHS94K.vIkBnTQ
    2
    CNfQy&oauth_version=1.0&sid=v2hChWPs3RN1VPOCOv3iEZDLv3p764g5fir9EQ-- HTTP/1.1
    Content-Type: application/json; charset=utf-8
    Host: rcore1.messenger.yahooapis.com
    Content-Length: 146
    Expect: 100-continue

    {"sendAs":"my_sender_here","action":"invite","ftSessionId":"FILE-TO-TRANSFER","target":"my_target_here","files":[{"fileName":"file.xml","fileSize":65}]}



    Response:
    CODE
    HTTP/1.1 403 Forbidden
    Date: Sun, 06 Feb 2011 17:46:19 GMT
    P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    cache-control: public,must-revalidate
    content-length: 110
    content-type: application/json;charset=utf-8
    Vary: Accept-Encoding
    Connection: close

    {"error":{"code":-1009,"detail":"Capability Check Error","description":"Capability Check Error"},"code":-1009}
    0
  • Thanks Pragy,

    setting the ClientCapability just solved the problem, now i am getting invite for file transfer, i will now try implementing the ACCEPT and File-transfer apis and hope all works well now.

    thanks a lot once again.







    QUOTE (jainpragya88 @ Feb 8 2011, 01:27 AM) <{POST_SNAPBACK}>
    Hello,

    Did you set clientCapability in Session Management API.If not then first you have to set then you can send file.

    for ex.
    string postdatas = "{\"presenceState\":0,\"presenceMessage\":\"my login status message\",\"clientCapabilities\":[{\"clientCapability\":\"fileXfer\"}]}";

    Thanks
    0
  • how did you do to obtaint token and relayIp?
    0
  • i'm getting error 400 at web response at the code above . do youknow why?...what am i doing wrong?
    0
  • how did u obtain file receive notification?
    0

Recent Posts

in Messenger IM SDK