Answered C# string question

SaeedP

Well-known member
Joined
Oct 21, 2020
Messages
99
Programming Experience
3-5
Hello,

Are the last parts of this code wrong?
I see red lines under some parts.
I doing this project in Blazor.

my code:
  public string resultMessage {get;set;}

var result = await _instaApi.UploadVideoAsync(mediaVideo, mediaImage,VideoUpload.captionVideo);

resultMessage = (result.Succeeded ?$ "Media created: {result.Value.Pk},{result.Value.Caption}"
        : $"Unable to upload video: {reult.Info.Message}");

And then:

C#:
<p>result:@resultMessage</p>

Thanks,

Saeed
 
Solution
One thing you should do, is; change how your code operates. And change your return type and how your calling code receives the result.

C#:
    public async Task StartUploadStory()
You would be better to return your result to the calling code that ran the upload task once it's finished.

I still suggest adding a MVC project to your Blazor app. You won't find many devs who do this, mainly because they don't know that you can use a MVC based web-app to drive your Blazor application. The performance decrease is barely noticeable, and it brings great functionality from using a MVC app. See : Using Blazor Components In An Existing MVC Application I've had more time to look at your code/post.

This : public static string...
One thing you should do, is; change how your code operates. And change your return type and how your calling code receives the result.

C#:
    public async Task StartUploadStory()
You would be better to return your result to the calling code that ran the upload task once it's finished.

I still suggest adding a MVC project to your Blazor app. You won't find many devs who do this, mainly because they don't know that you can use a MVC based web-app to drive your Blazor application. The performance decrease is barely noticeable, and it brings great functionality from using a MVC app. See : Using Blazor Components In An Existing MVC Application I've had more time to look at your code/post.

This : public static string storyUpload { get; set; } and : <input type="file" id="sUpload" @bind="storyUpload" @bind:event="oninput" />. Why are you using a string, and where are you encoding your data or reading it into a memorystream to upload? If you are uploading a datastream of any kind to Instagram, or any other server, you would send a datastream and not a string. Most servers also expect the sender to upload encoded data too.

While Blazor doesn't require the traditional action url and post method. I would personally write it like so. That said, as you will see in this documentation, you don't have to do it as I am recommending : ASP.NET Core Blazor file uploads - Hopefully this will give you some pointers to put you on track.

I should also warn you that uploading to Instagram VIA any application other than their own app is a violation of their TOS, and they will ban the application upon detection along with the account used. And be sure, they will detect your upload when they check the signature of the upload. This is not something you can circumvent, nor would I expect anyone here to help you try. You should respect the TOS set-forth by any company.
 
Solution
One thing you should do, is; change how your code operates. And change your return type and how your calling code receives the result.

C#:
    public async Task StartUploadStory()
You would be better to return your result to the calling code that ran the upload task once it's finished.

I still suggest adding a MVC project to your Blazor app. You won't find many devs who do this, mainly because they don't know that you can use a MVC based web-app to drive your Blazor application. The performance decrease is barely noticeable, and it brings great functionality from using a MVC app. See : Using Blazor Components In An Existing MVC Application I've had more time to look at your code/post.

This : public static string storyUpload { get; set; } and : <input type="file" id="sUpload" @bind="storyUpload" @bind:event="oninput" />. Why are you using a string, and where are you encoding your data or reading it into a memorystream to upload? If you are uploading a datastream of any kind to Instagram, or any other server, you would send a datastream and not a string. Most servers also expect the sender to upload encoded data too.

While Blazor doesn't require the traditional action url and post method. I would personally write it like so. That said, as you will see in this documentation, you don't have to do it as I am recommending : ASP.NET Core Blazor file uploads - Hopefully this will give you some pointers to put you on track.

I should also warn you that uploading to Instagram VIA any application other than their own app is a violation of their TOS, and they will ban the application upon detection along with the account used. And be sure, they will detect your upload when they check the signature of the upload. This is not something you can circumvent, nor would I expect anyone here to help you try. You should respect the TOS set-forth by any company.

Dear Sheepings,

Thank you for your and links help. I will consider using MVC for my projects. There aren't many resources about this method(using MVC with Blazor).
I will publish this site under the supervision of the Facebook company.

Can you explain more about my mistake in using string for upload? I need your info and help.

Thanks;
 
Last edited by a moderator:
I think that the reason why he is using a string is because he is using that (illegal/unofficial?) InstaSharper API name UploadStoryPhotoAsyc() which take an InstaImage object that happens to just hold a URL, rather than a data stream.
 
Can you explain more about my mistake in using string for upload? I need your info and help.
It may not necessarily be a mistake given what @Skydiver is highlighting above. Since I don't know anything about the API, you are using. And given it's an (unofficial) API, it may already be blocked by Facebook who own Instagram. Hence why it's not working for you. That's just an assumption on my part.

It's common practice when uploading a file, that you send the file as a datastream to the server you are uploading too. Those datasteams are commonly encoded with base64/other encryption methods when stored on the server. The API, you are using according to Skydiver, is using a string. Since I don't know how the file is handled in the API from that string, I can't help you further with this issue, as this is becoming a third party issue and not a C# specific issue. Nor would I be interested in helping someone to circumvent and violate the policies of any companies terms of service.

Sorry, but we will have to park this one here.
 
Back
Top Bottom