Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Checking And Saving A File In S3

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: Checking And Saving A File In S3

    function itemName as c (e as p)
    '-- checks to see if filename exists in S3

    dim ConnectionString as C = "Provider='Disk';Container='Z:\items';"
    dim ResultData as B
    dim ContentType as C
    dim Container as A5Storage::DataContainer = null_value()
    dim Item as A5Storage::DataItem = null_value()
    dim newName as c = e._itemName
    dim URL as c
    dim sql as c
    dim args as sql::arguments
    dim flag as l

    dim globalcn as sql::connection
    flag = globalcn.open("::Name::conn")

    args.set("CURRENTITEMID", e.dataSubmitted.itemid)
    CallResult = A5Storage::DataContainer::Open(Container, \
    "Provider='Disk';Container='Z:\items';")
    if CallResult.Success then
    if Container.ItemExists(newName") then
    newName = newName + "1"
    end if
    Item.SaveToFile("Z:\items\"+newName)
    URL = "https://s3.amazonaws.com/items/" + newName
    sql = "UPDATE items SET URL = '" + URL + "' where ID = :CURRENTITEMID"
    flag = globalcn.execute(sql,args)
    end if

    globalcn.close()

    end function

    Comment


      #17
      Re: Checking And Saving A File In S3

      Still getting the XHR Error, this is what I have: What do you use to check if filename exists in S3?

      function ItemName as v (e as p)
      '-- checks to see if filename exists in S3

      dim ConnectionString as C = "Provider='Disk';Container='Z:\items';"
      dim ResultData as B
      dim ContentType as C
      dim Container as A5Storage::DataContainer = null_value()
      dim Item as A5Storage::DataItem = null_value()
      dim newName as c = e._itemName
      dim URL as c
      dim sql as c
      dim args as sql::arguments
      dim flag as l

      dim globalcn as sql::connection
      globalcn.open("::Name::conn")

      args.set("CURRENTITEMID", e.dataSubmitted.itemid)
      CallResult = A5Storage::DataContainer::Open(Container, \
      "Provider='Disk';Container='Z:\items';")
      if CallResult.Success then
      if Container.ItemExists("e._itemName") then
      newName = newName + "1"
      end if
      Item.SaveToFile("Z:\items\"+newName)
      URL = "https://s3.amazonaws.com/items/" + newName
      sql = "UPDATE items SET URL = '" + URL + "' where ID = :CURRENTITEMID"
      flag = globalcn.execute(sql,args)
      end if

      globalcn.close()

      end function

      Comment


        #18
        Re: Checking And Saving A File In S3

        As I said before, I don't use these methods so maybe someone else will chime in that has experience. According to the documentation, .ItemExists is how to determine if the file is already there. For now, let's add some return javascript to see if we can get more info on the error (revised function below). Beyond that, I'd turn off security and debug the function.


        function itemName as c (e as p)
        '-- checks to see if filename exists in S3

        dim ConnectionString as C = "Provider='Disk';Container='Z:\items';"
        dim ResultData as B
        dim ContentType as C
        dim Container as A5Storage::DataContainer = null_value()
        dim Item as A5Storage::DataItem = null_value()
        dim newName as c = e._itemName
        dim URL as c
        dim sql as c
        dim args as sql::arguments
        dim flag as l
        dim js as c

        dim globalcn as sql::connection
        flag = globalcn.open("::Name::conn")
        if flag = .f. then
        js = "A5.msgBox.show('Error','Error reported was: " + js_escape(globalcn.CallResult.text) + "','o');"
        itemName = js
        exit function
        end if

        args.set("CURRENTITEMID", e.dataSubmitted.itemid)
        CallResult = A5Storage::DataContainer::Open(Container, \
        "Provider='Disk';Container='Z:\items';")
        if CallResult.Success then
        if Container.ItemExists(newName") then
        newName = newName + "1"
        end if
        Item.SaveToFile("Z:\items\"+newName)
        if .not. Item.SaveToFile("c:\mydata.jpg)
        js = "A5.msgBox.show('Error','Error reported was: " + js_escape(Item.CallResult.text) + "','o');"
        end if
        URL = "https://s3.amazonaws.com/items/" + newName
        sql = "UPDATE items SET URL = '" + URL + "' where ID = :CURRENTITEMID"
        flag = globalcn.execute(sql,args)
        else
        js = "A5.msgBox.show('Error','Could not open container.','o');"
        end if

        globalcn.close()

        itemName = js

        end function

        Comment


          #19
          Re: Checking And Saving A File In S3

          I also notice you still have the function set as void. Change it to return a character string as in my example.

          Comment


            #20
            Re: Checking And Saving A File In S3

            At this point I've exhausted my resources. If the revised function above doesn't return any useful information about the error then why don't you just debug it in your browser?

            Comment


              #21
              Re: Checking And Saving A File In S3

              Originally posted by TheDuke View Post
              As I said before, I don't use these methods so maybe someone else will chime in that has experience. According to the documentation, .ItemExists is how to determine if the file is already there. For now, let's add some return javascript to see if we can get more info on the error (revised function below). Beyond that, I'd turn off security and debug the function.


              function itemName as c (e as p)
              '-- checks to see if filename exists in S3

              dim ConnectionString as C = "Provider='Disk';Container='Z:\items';"
              dim ResultData as B
              dim ContentType as C
              dim Container as A5Storage::DataContainer = null_value()
              dim Item as A5Storage::DataItem = null_value()
              dim newName as c = e._itemName
              dim URL as c
              dim sql as c
              dim args as sql::arguments
              dim flag as l
              dim js as c

              dim globalcn as sql::connection
              flag = globalcn.open("::Name::conn")
              if flag = .f. then
              js = "A5.msgBox.show('Error','Error reported was: " + js_escape(globalcn.CallResult.text) + "','o');"
              itemName = js
              exit function
              end if

              args.set("CURRENTITEMID", e.dataSubmitted.itemid)
              CallResult = A5Storage::DataContainer::Open(Container, \
              "Provider='Disk';Container='Z:\items';")
              if CallResult.Success then
              if Container.ItemExists(newName") then
              newName = newName + "1"
              end if
              Item.SaveToFile("Z:\items"+newName)
              if .not. Item.SaveToFile("c:\mydata.jpg)
              js = "A5.msgBox.show('Error','Error reported was: " + js_escape(Item.CallResult.text) + "','o');"
              end if
              URL = "https://s3.amazonaws.com/items/" + newName
              sql = "UPDATE items SET URL = '" + URL + "' where ID = :CURRENTITEMID"
              flag = globalcn.execute(sql,args)
              else
              js = "A5.msgBox.show('Error','Could not open container.','o');"
              end if

              globalcn.close()

              itemName = js

              end function
              I can't see how this code runs... or could have been tested... as there are syntax errors within the code.

              Does it run successfully?

              Comment


                #22
                Re: Checking And Saving A File In S3

                No it isnt working. Seems kind of complex on what is trying to be achieved here.

                Comment


                  #23
                  Re: Checking And Saving A File In S3

                  Instead of using this function, why not use the builtin 'File Upload - Amazon S3 Storage or Alpha Anywhere Server' action javascript? You should get a unique file name prior to uploading and not try to append something if it already exists on S3. If you want to upload fname and it exists then you're wanting to make it fname1 but what if that exists? Then you've got fname11, fname111... where does it end? Use a unique id from the table you're storing the image path in.

                  Comment


                    #24
                    Re: Checking And Saving A File In S3

                    Originally posted by swest View Post
                    No it isnt working. Seems kind of complex on what is trying to be achieved here.
                    It's actually a little unclear what you want to achive. The post title reads "Checking and Saving a File In S3" but none of the code posted gets anywhere near an S3 Bucket.

                    Do you want to check a file upload against an S3 Bucket to determine if the filename being uploaded already exists in S3?
                    Do you want to check a file upload against a local folder of files?

                    Comment


                      #25
                      Re: Checking And Saving A File In S3

                      Yes want to check in a S3 bucket to see if a file name already exists and if it does rename that file so it doesn’t overwrite the existing file. So if truck.jpg already exists and another user is uploading truck.jpg then it automatically renamed it to truck1.jpg or something.

                      Comment


                        #26
                        Re: Checking And Saving A File In S3

                        Originally posted by swest View Post
                        Yes want to check in a S3 bucket to see if a file name already exists and if it does rename that file so it doesn’t overwrite the existing file. So if truck.jpg already exists and another user is uploading truck.jpg then it automatically renamed it to truck1.jpg or something.
                        I'm assuming you're using the File Upload - Amazon S3 Storage Action... since I believe it's the only File Upload Action containing an After file select event... but you don't actually confirm it. If that's the case, and as David suggests, use the "Target object name of Amazon S3" property to give the file a unique name... a timestamp... a prefix/suffix... something.

                        Comment


                          #27
                          Re: Checking And Saving A File In S3

                          Would I do an ajax callback to a XBasic function to set the e.name to something else? Maybe set a variable to id which is a primary key in my table and then do like newName = e.name + id?

                          Comment


                            #28
                            Re: Checking And Saving A File In S3

                            How would I though change the name of the physical file that is uploaded to S3? Would I return newName from the XBasic function set e.name in "Target object name of Amazon S3"?

                            Comment


                              #29
                              Re: Checking And Saving A File In S3

                              You can do pretty anything you'd like... just return whatever name you come up with. E.g. If I choose apple.jpg and I have a counter namespace variable going... then I can do this...

                              Code:
                              var ulCnt = {dialog.Object}.__S3Cnt;
                              
                              var arr = e.name.split('.')
                              arr[0] = arr[0] + '_' + ulCnt + '_' + A5.ts();
                              var name = arr.join('.');
                              
                              {dialog.Object}.__S3Cnt = ulCnt + 1;
                              
                              return name;
                              which will result in a completely unique S3 filename of...

                              Code:
                              apple_1_jdsbyrk5.jpg

                              Comment


                                #30
                                Re: Checking And Saving A File In S3

                                I put this below in "Target object name of Amazon S3' but am still getting XHR error:

                                var ulCnt = {dialog.Object}.__S3Cnt;

                                var arr = e.name.split('.')
                                arr[0] = arr[0] + '_' + ulCnt + '_' + A5.ts();
                                var name = arr.join('.');

                                {dialog.Object}.__S3Cnt = ulCnt + 1;

                                return name;

                                Comment

                                Working...
                                X