Regarding issue on passing endpoint into angularjs

Hello experts,

I have an  endpoint  API  below which checks the inappropriate content in a video

POST 'https://api.sightengine.com/1.0/moderation.json' 
 'api_user={api_user}' \
 'api_secret={api_secret}' \
 'media=@/path/to/local/file.jpg'

Open in new window


I want to pass this  above endpoint API  mark below  space  of my comments through angularjs application which can verify the uploaded file with the inappropriate content in it.let us know through the snippet of code… Pls find my code  below





export class VideoUploadService {
  public videup: VideoUpload;
  constructor(private http: Http, private router: Router, @Inject('videoUploadEndPoint') private videoUploadUrl) { }
  requestUrl: string;
  responseData: any;
  //handleError: any;
  postVideoData(file: any, title: any, videoCatgy: any, country: any, language: any, starttime: any, endtime: any, duration: any) {
    var formData: any = new FormData();
    formData.append("uploadFileName", file, file.name);//alert(file.name);

   // verifying the video content with Sightengine  endpoint from here onwards. Let us   
    know..



formData.append('videoTitle', title);
 formData.append('videoCatgy', videoCatgy);
 formData.append('userName', 'testuser');
 formData.append('startTmName', starttime);
 formData.append('endTmName', endtime);
 formData.append('durClpName', duration);
  var returnReponse = new Promise((resolve, reject) => {
     this.http.post(this.videoUploadUrl + 'videoclip/', formData, {
        // headers: headers
      }).subscribe(
        res => {//console.log(res.json());

          this.responseData = res.json();
          resolve(this.responseData);
          this.router.navigate(['']);
        },
        error => {
          this.router.navigate(['']);
          reject(error);
        }
        );
    });

  }
  private extractData(res: Response) {
    let body = res.json();

    return body || {};
  }

  private handleError(error: Response | any) {
    let errMsg: string;
    if (error instanceof Response) {
      const body = error.json() || '';
      const err = body.error || JSON.stringify(body);
      errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    console.error(errMsg);
    return Observable.throw(errMsg);
  }

} 

Open in new window

roy_sanudeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
I am not sure what the question is - can you elaborate?
0
roy_sanudeveloperAuthor Commented:
Thank you Julian for your response.
we have an application which uploads videos but  our idea is to verify the videos  content using
third party tool such as sightengine(https://sightengine.com/) which has API which verify the inappropriate content if the video has.
The third party product has an api which verify the local videos and streams from the nodejs
                  POST 'https://api.sightengine.com/1.0/moderation.json'
                  'api_user={api_user}' \
                'api_secret={api_secret}' \
                'media=@/path/to/local/file.jpg'

My question is it possible to pass this end point through angularjs application instead of nodejs . I have an upload function above. let us know your idea

Thank you so much for your response...
0
Julian HansenCommented:
Trying to understand why you want to do this from Angular - there are many reasons i can think of why this is not a good idea

1. The video would have to be on the server so sightengine can see it - which puts it in the domain of the server
2. Sightengine endpoint looks like it needs authentication - so you don't want that in your Angular code
3. I would imagine that the check on the video would be triggered on the upload of the video - this would imply putting the video into a pending queue on the server and a process being kicked off with SightEngine to check it - there might be a delay with that

Trying to see the use case for running this from Angular. I would imagine the process to work like this
1. Upload video
2. Server saves video in pending location
2. Server initiates call to SE
3. Server receives response from SE
4. Server approves / rejects video and updates status
5. Server notifies client (socket) that status on video has changed

This is just a guess though I don't know what your system does.

If you have to do a request from Angular then I would setup a Node service that proxies the call - Angular calls that and it calls SE - keeps the auth data on the server where it belongs.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

roy_sanudeveloperAuthor Commented:
We deploy all the videos in AWS S3 bucket

The process  would be something like I guess

1. Upload videos
2. Server saves videos in pending location
2. Server initiates call to SE
3. Server receives response from SE
4. Server approved videos will go to the S3 bucket.
0
Julian HansenCommented:
Fine, but that is all server side - still need to understand why you need to call SE from Angular. Surely Angular's involvement is in getting the Video from the user and uploading it - the rest should be on the server side.

Have you looked at Amazon Lambda functions - where you can write code to act on an event - like a video upload - that automatically does whatever you need it to?
0
roy_sanudeveloperAuthor Commented:
Yes it is not safe to do it from angularjs side   I think ...Yes we use lambda function which trigger to do that..
0
Julian HansenCommented:
Then I am a bit lost as to what the question is because I thought it was about AngularJS making the call to SE?
0
roy_sanudeveloperAuthor Commented:
I had a discussion with SE guys they inform me  by the words below

"Our users typically submit the videos from their own servers, not from the client code. So not from angularjs but from the code on your back-end that processes the videos."
0
roy_sanudeveloperAuthor Commented:
i am guessing this  piece for code to verify from the nodejs side would be the right one below.. let us know your comments or any other idea to pass   endpoint    POST 'https://api.sightengine.com/1.0/moderation.json' from nodejs..


// 
Set your API_USER and API_SECRET values here. See http://sightengine.com to create your account
var API_USER = "sam";
var API_SECRET = "secretkey";

var SightengineClient = require ('./sightengine');
var Sightengine = new SightengineClient(API_USER, API_SECRET);

var imagepath = "/path/to/image.jpg";
Sightengine.checkNudityForFile(imagepath, function(error, result) {
  if(error) console.dir(error);
  else console.log(result);
});

Open in new window

0
Julian HansenCommented:
Our users typically submit the videos from their own servers, not from the client code. So not from angularjs but from the code on your back-end that processes the videos.
That sounds about right.

Regarding whether the Node.js code is right - I cannot say - it looks fine but then I am not versed enough in the SE service to say for sure.

The best way to find out is to test the code and see what it returns.

If you don't come right with that then close this question and open another one with NodeJS as the Topic area so that you can get more eyes on the problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Angular

From novice to tech pro — start learning today.