File Upload in .Net with App Authentication



1 comment

  • Casper Fabricius

    Hi Jan,

    Your code looks correct. It could be a whole lot simpler, but unfortunately the .NET client is far from done, and we don't have resources to improve it at the moment.

    My best at guess at why it wouldn't work with app auth, when it works with others types of auth, is that you are not authenticating as the correct app, e.g. you are not authenticated as the app of the item you are trying to update. Settings rights on anything will not help you, that should really be a read-only property since rights are just information from the API, not something you can change.

    I know for a fact that adding files to an item using app authentication works, because that's exactly what happens here in our sample MVC project. You can try and get that running an play around with that - you can use your own app auth and grab as much code as you need from that project, it's all MIT licensed.

    The easiest way to add an uploaded file to an existing item is to use the attach file operation. It's not implemented in the .NET lib yet, but you should be able to use the operation in any case with code similar to this:


    public struct AttachRequest


    [DataMember(IsRequired = false, Name = "ref_id")]

    public int RefId { get; set; }
    [DataMember(IsRequired = false, Name = "ref_type")]

    public string RefType { get; set; }

    var fileId = 1234;

    var itemId = 5678;

    var requestData = new AttachRequest() {

    RefId = itemId,

    RefType = "item"

    PodioRestHelper.JSONRequest<object>(Constants.PODIOAPI_BASEURL + "/file/" + file_id + "/attach", _client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST);

    I haven't tried out the above code (I'm not on a .NET dev), but it should work - a few tweaks are probably required ;)

    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk