0

I use angularjs to get a string from a web service. This string is actually a base64 pdf file.

public string Get(int id)
{
    var bytes = File.ReadAllBytes(@"C:\test.pdf");
    var content = Convert.ToBase64String(bytes);
    return content;
}

Angularjs return me a array like this one:

{"0":"\"","1":"J","2":"V","3":"B","4":"E" ...}

But I need a complete string like this : "JVBE..."

I try to find a way to get the complete string instead of array format and I don't find anything.

Do you know how handle this?

Thank you!

Karine

2
  • I don't see any Angular JS code here.. either no Javascript... It looks like you are mixing Java & Javascript. There is no var keyword in Java and so no File.ReadAllBytes() function in Javascript. Your Get function must return an error at execution/compilation.. Commented Oct 16, 2014 at 17:03
  • @Lorenzo, actually it looks like C# code (there is var in C#). But you're right anyway, no JS here at all :) Commented Oct 16, 2014 at 17:32

1 Answer 1

2

It seems that you are returning data from .Net MVC's Web API. You can do

public object Get(int id)
{
    var bytes = File.ReadAllBytes(@"C:\test.pdf");
    var content = Convert.ToBase64String(bytes);
    return new {value = content};
}

Since a string can't be converted to JSON.

Sign up to request clarification or add additional context in comments.

2 Comments

That give a anonymous return type... Are you sure this is the good way?
@Karine If that is your C# code of your web API, then the answer is yes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.